-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve error handling (including collectionName not found)
- Loading branch information
Showing
3 changed files
with
46 additions
and
53 deletions.
There are no files selected for viewing
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,46 +1,37 @@ | ||
import axios, { AxiosError } from 'axios' | ||
import axios from 'axios' | ||
import config from '../../../config' | ||
import { type ChatConversation } from '../../types' | ||
import { type LlmCompletion } from './llmApi' | ||
|
||
const API_ENDPOINT = config.llms.apiEndpoint | ||
const API_ENDPOINT = config.llms.apiEndpoint // http://localhost:8080' // config.llms.apiEndpoint | ||
|
||
export const vertexCompletion = async ( | ||
conversation: ChatConversation[], | ||
model = config.llms.model | ||
): Promise<LlmCompletion> => { | ||
try { | ||
const data = { | ||
model, // chat-bison@001 'chat-bison', //'gpt-3.5-turbo', | ||
stream: false, | ||
messages: conversation | ||
} | ||
const url = `${API_ENDPOINT}/vertex/completions` | ||
const response = await axios.post(url, data) | ||
if (response) { | ||
const totalInputTokens = 4 // response.data.usage.prompt_tokens; | ||
const totalOutputTokens = 5 // response.data.usage.completion_tokens; | ||
return { | ||
completion: { | ||
content: response.data._prediction_response[0][0].candidates[0].content, | ||
author: 'bot', | ||
model | ||
}, | ||
usage: totalOutputTokens + totalInputTokens, | ||
price: 0 | ||
} | ||
} | ||
const data = { | ||
model, // chat-bison@001 'chat-bison', //'gpt-3.5-turbo', | ||
stream: false, | ||
messages: conversation | ||
} | ||
const url = `${API_ENDPOINT}/vertex/completions` | ||
const response = await axios.post(url, data) | ||
if (response) { | ||
const totalInputTokens = 4 // response.data.usage.prompt_tokens; | ||
const totalOutputTokens = 5 // response.data.usage.completion_tokens; | ||
return { | ||
completion: undefined, | ||
usage: 0, | ||
completion: { | ||
content: response.data._prediction_response[0][0].candidates[0].content, | ||
author: 'bot', | ||
model | ||
}, | ||
usage: totalOutputTokens + totalInputTokens, | ||
price: 0 | ||
} | ||
} catch (error: any) { | ||
if (error instanceof AxiosError) { | ||
console.log(error.code) | ||
console.log(error.message) | ||
console.log(error.stack) | ||
} | ||
throw error | ||
} | ||
return { | ||
completion: undefined, | ||
usage: 0, | ||
price: 0 | ||
} | ||
} |
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