Skip to content

Commit

Permalink
chore: fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
luoling8192 committed Dec 14, 2024
1 parent 25adc77 commit 2a03684
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 15 deletions.
8 changes: 4 additions & 4 deletions packages/neuri/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"import": "./dist/index.mjs"
},
"./openai": {
"types": "./dist/openai.d.ts",
"import": "./dist/openai.mjs"
"types": "./dist/openai/index.d.ts",
"import": "./dist/openai/index.mjs"
},
"./test": {
"types": "./dist/test.d.ts",
Expand Down Expand Up @@ -69,8 +69,8 @@
"@typeschema/zod": "^0.14.0",
"json-schema": "^0.4.0",
"remark": "^15.0.1",
"valibot": "^0.42.1",
"zod": "^3.23.8",
"zod-to-json-schema": "^3.23.5",
"valibot": "^0.42.1"
"zod-to-json-schema": "^3.23.5"
}
}
9 changes: 7 additions & 2 deletions packages/neuri/src/openai-xsai/agent.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { env } from 'node:process'
import { createOpenAI } from '@xsai/providers'
import { description, object, pipe, string } from 'valibot'
import { describe, expect, it } from 'vitest'
Expand All @@ -7,11 +8,15 @@ import { defineToolFunction } from './tools'

describe('openai-xsai/agent', () => {
it('should execute call', async () => {
const apiKey = process.env.VITE_OPENAI_API_KEY || process.env.OPENAI_API_KEY
const baseURL = process.env.VITE_OPENAI_API_BASEURL || process.env.OPENAI_API_BASEURL
const apiKey = env.OPENAI_API_KEY || env.VITE_OPENAI_API_KEY
let baseURL = env.OPENAI_API_BASEURL || env.VITE_OPENAI_API_BASEURL
expect(apiKey).toBeDefined()
expect(baseURL).toBeDefined()

if (!baseURL?.endsWith('/')) {
baseURL += '/'
}

const openAI = createOpenAI({
apiKey: apiKey!,
baseURL: baseURL!,
Expand Down
9 changes: 7 additions & 2 deletions packages/neuri/src/openai-xsai/generate.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { env } from 'node:process'
import { createOpenAI } from '@xsai/providers'
import { describe, expect, it } from 'vitest'
import { generate } from './generate'
import { messages, system, user } from './messages'

describe('generate', () => {
it('should generate text', async () => {
const apiKey = process.env.VITE_OPENAI_API_KEY || process.env.OPENAI_API_KEY
const baseURL = process.env.VITE_OPENAI_API_BASEURL || process.env.OPENAI_API_BASEURL
const apiKey = env.OPENAI_API_KEY || env.VITE_OPENAI_API_KEY
let baseURL = env.OPENAI_API_BASEURL || env.VITE_OPENAI_API_BASEURL
expect(apiKey).toBeDefined()
expect(baseURL).toBeDefined()

if (!baseURL?.endsWith('/')) {
baseURL += '/'
}

// TODO: fix baseURL
// TODO: fix 404 error
const openAI = createOpenAI({
Expand Down
20 changes: 20 additions & 0 deletions packages/neuri/src/openai-xsai/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ export function imagePart(imageUrl: string): ImagePart {
return { type: 'image_url', image_url: { url: imageUrl } }
}

// TODO: AssistantMessage
// export function assistant(toolCall: OpenAI.Chat.ChatCompletionMessageToolCall | undefined): { role: 'assistant', tool_calls: OpenAI.Chat.ChatCompletionMessageToolCall[], name?: string }
// export function assistant(message: string): { role: 'assistant', content: string, name?: string }
// export function assistant(body: string | OpenAI.Chat.ChatCompletionMessageToolCall | undefined): OpenAI.ChatCompletionAssistantMessageParam {
// if (body == null)
// return { role: 'assistant', content: '' }
// if (typeof body === 'string')
// return { role: 'assistant', content: body }

// return { role: 'assistant', tool_calls: [body] }
// }

// export function tool<P = any, R = any>(message: string, toolCall: ResolvedToolCall<P, R>): OpenAI.ChatCompletionToolMessageParam {
// return {
// role: 'tool',
// content: message,
// tool_call_id: toolCall.toolCall.id,
// }
// }

export function messages(...messages: Message[]): Message[] {
return messages
}
25 changes: 18 additions & 7 deletions packages/neuri/src/openai-xsai/stream.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { env } from 'node:process'
import { createOpenAI } from '@xsai/providers'
import { describe, expect, it } from 'vitest'
import { messages, system, user } from './messages'
import { stream } from './stream'

describe('stream', () => {
it('should stream textStream', async () => {
const apiKey = process.env.VITE_OPENAI_API_KEY || process.env.OPENAI_API_KEY
const baseURL = process.env.VITE_OPENAI_API_BASEURL || process.env.OPENAI_API_BASEURL
const apiKey = env.OPENAI_API_KEY || env.VITE_OPENAI_API_KEY
let baseURL = env.OPENAI_API_BASEURL || env.VITE_OPENAI_API_BASEURL
expect(apiKey).toBeDefined()
expect(baseURL).toBeDefined()

if (!baseURL?.endsWith('/')) {
baseURL += '/'
}

// TODO: fix baseURL
const openAI = createOpenAI({
apiKey: apiKey!,
baseURL: baseURL!,
baseURL,
})

const { textStream } = await stream({
Expand All @@ -38,13 +43,19 @@ describe('stream', () => {

// TODO: auto tee?
it('should stream chunkStream', async () => {
expect(process.env.VITE_OPENAI_API_KEY).toBeDefined()
expect(process.env.VITE_OPENAI_API_BASEURL).toBeDefined()
const apiKey = env.OPENAI_API_KEY || env.VITE_OPENAI_API_KEY
let baseURL = env.OPENAI_API_BASEURL || env.VITE_OPENAI_API_BASEURL
expect(apiKey).toBeDefined()
expect(baseURL).toBeDefined()

if (!baseURL?.endsWith('/')) {
baseURL += '/'
}

// TODO: fix baseURL
const openAI = createOpenAI({
apiKey: process.env.VITE_OPENAI_API_KEY!,
baseURL: process.env.VITE_OPENAI_API_BASEURL!,
apiKey: apiKey!,
baseURL: baseURL!,
})

const { chunkStream } = await stream({
Expand Down

0 comments on commit 2a03684

Please sign in to comment.