Skip to content

Commit

Permalink
fix: ut
Browse files Browse the repository at this point in the history
  • Loading branch information
nekomeowww committed Dec 18, 2024
1 parent e50e27a commit 435474f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
5 changes: 3 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
VITE_OPENAI_API_KEY=''
VITE_OPENAI_API_BASEURL=''
OPENAI_API_BASEURL=''
OPENAI_API_KEY=''
SERPAPI_API_KEY=''
6 changes: 2 additions & 4 deletions packages/neuri/src/openai/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { CommonProviderOptions } from '@xsai/providers'
import type { Message } from '@xsai/shared-chat'

import type { ChatCompletion, DefinedTool } from './types'
import { chatCompletion } from '@xsai/shared-chat'
import { chatCompletionFromOpenAIChatCompletion, resolveFirstToolCallFromCompletion } from './completion'
import { generate } from './generate'
import { invokeFunctionWithTools } from './invoke'
import { assistant, tool } from './messages'
import { tools } from './tools'
Expand All @@ -17,16 +17,14 @@ export function composeAgent(options: {
while (max >= 0) {
max--

const reqRes = await chatCompletion({
const res = await generate({
apiKey: options.provider.apiKey,
baseURL: options.provider.baseURL,
model: callOptions.model,
messages,
tools: tools(options.tools),
})

const res = await reqRes.json() as ChatCompletion

const resChatCompletionToolCall = resolveFirstToolCallFromCompletion(res)
if (!resChatCompletionToolCall)
return res
Expand Down
14 changes: 14 additions & 0 deletions packages/neuri/src/openai/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { GenerateTextOptions } from '@xsai/generate-text'
import type { ChatCompletion } from './types'
import { chatCompletion } from '@xsai/shared-chat'

/**
* Generate text
*
* @param params - The parameters to generate text.
* @returns ChatCompletion
*/
export async function generate(params: GenerateTextOptions) {
const reqRes = await chatCompletion(params)
return await reqRes.json() as ChatCompletion
}
2 changes: 0 additions & 2 deletions packages/neuri/src/openai/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ async function* asyncIteratorFromReadableStream<T, F = Uint8Array>(res: Readable
* Stream the completion response from LLM API.
*
* @param params - The parameters to stream the completion response.
* @param params.provider - The provider options.
* @param params.options - The options to create the completion.
* @returns The completion response stream.
*/
export async function stream(params: StreamTextOptions): Promise<StreamResponse> {
Expand Down

0 comments on commit 435474f

Please sign in to comment.