-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix model select seprate fim chat urls
- Loading branch information
1 parent
2b59787
commit 26b122f
Showing
7 changed files
with
90 additions
and
76 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,40 @@ | ||
import { workspace } from 'vscode' | ||
import { Logger } from '../common/logger' | ||
import { ApiModels } from '../common/types' | ||
|
||
export class OllamaService { | ||
private logger : Logger | ||
private logger: Logger | ||
private _config = workspace.getConfiguration('twinny') | ||
private _apiHostname = this._config.get('apiHostname') as string | ||
private _chatApiPort = this._config.get('chatApiPort') as string | ||
private _fimApiPort = this._config.get('fimApiPort') as string | ||
private _useTls = this._config.get('useTls') as boolean | ||
private _baseUrl: string | ||
private _baseUrlChat: string | ||
private _baseUrlFim: string | ||
|
||
constructor () { | ||
constructor() { | ||
this.logger = new Logger() | ||
const useTls = this._useTls; | ||
const port = this._chatApiPort || this._fimApiPort | ||
const protocol = useTls ? 'https' : 'http'; | ||
this._baseUrl = `${protocol}://${this._apiHostname}:${port}` | ||
const useTls = this._useTls | ||
const protocol = useTls ? 'https' : 'http' | ||
this._baseUrlChat = `${protocol}://${this._apiHostname}:${this._chatApiPort}` | ||
this._baseUrlFim = `${protocol}://${this._apiHostname}:${this._fimApiPort}` | ||
} | ||
|
||
public fetchModels = async (resource = '/api/tags'): Promise<ApiModels> => { | ||
const res = await fetch(this._baseUrl + resource) | ||
if (!res.ok) { | ||
this.logger.error(new Error(`${res.status}`)) | ||
throw Error('Failed to get ollama models') | ||
public fetchModels = async (resource = '/api/tags') => { | ||
const chatModelsRes = (await fetch(this._baseUrlChat + resource)) || [] | ||
const fimModelsRes = await fetch(this._baseUrlFim + resource) | ||
const { models: chatModels } = await chatModelsRes.json() | ||
const { models: fimModels } = await fimModelsRes.json() | ||
const models = new Set() | ||
if (Array.isArray(chatModels)) { | ||
for (const model of chatModels) { | ||
models.add(model) | ||
} | ||
} | ||
return await res.json() | ||
if (Array.isArray(fimModels)) { | ||
for (const model of fimModels) { | ||
models.add(model) | ||
} | ||
} | ||
return Array.from(models) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters