Skip to content

Commit 1f6e587

Browse files
committed
add test tool function call
1 parent 4e2fe13 commit 1f6e587

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

src/server/routes/openai.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import multer from 'multer'
44
import { CourseChatRequest, RequestWithUser } from '../types'
55
import { isError } from '../util/parser'
66
import { calculateUsage, incrementUsage, checkUsage, checkCourseUsage, incrementCourseUsage } from '../services/chatInstances/usage'
7-
import { getCompletionEvents, streamCompletion } from '../util/azure'
8-
import { streamResponsesEvents, getResponsesEvents } from '../util/azureV2'
7+
import { getCompletionEvents, streamCompletion } from '../util/azure/client'
8+
import { streamResponsesEvents, getResponsesEvents } from '../util/azure/clientV2'
99
import { getMessageContext, getModelContextLimit, getCourseModel, getAllowedModels } from '../util/util'
1010
import getEncoding from '../util/tiktoken'
1111
import logger from '../util/logger'

src/server/services/rag/query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EMBED_MODEL } from '../../../config'
22
import { RagIndex } from '../../db/models'
3-
import { getAzureOpenAIClient } from '../../util/azure'
3+
import { getAzureOpenAIClient } from '../../util/azure/client'
44
import { getOllamaOpenAIClient } from '../../util/ollama'
55
import { fullTextSearchChunks, vectorSearchKChunks } from './chunkDb'
66
import { getEmbeddingVector } from './embed'

src/server/util/azure.ts renamed to src/server/util/azure/client.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { OpenAIClient, AzureKeyCredential, EventStream, ChatCompletions, GetEmbe
22
import { Tiktoken } from '@dqbd/tiktoken'
33
import { Response } from 'express'
44

5-
import { AzureOptions, APIError } from '../types'
6-
import { AZURE_RESOURCE, AZURE_API_KEY } from './config'
7-
import { validModels, inProduction } from '../../config'
8-
import logger from './logger'
5+
import { AzureOptions, APIError } from '../../types'
6+
import { AZURE_RESOURCE, AZURE_API_KEY } from '../config'
7+
import { validModels, inProduction } from '../../../config'
8+
import logger from '../logger'
99
import { AzureOpenAI } from 'openai'
1010

1111
const endpoint = `https://${AZURE_RESOURCE}.openai.azure.com/`

src/server/util/azureV2.ts renamed to src/server/util/azure/clientV2.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Tiktoken } from '@dqbd/tiktoken'
22
import { Response } from 'express'
33

4-
import { AZURE_RESOURCE, AZURE_API_KEY } from './config'
5-
import { validModels, inProduction } from '../../config'
6-
import logger from './logger'
4+
import { AZURE_RESOURCE, AZURE_API_KEY } from '../config'
5+
import { validModels, inProduction } from '../../../config'
6+
import logger from '../logger'
77

8-
import { APIError } from '../types'
8+
import { APIError } from '../../types'
99
import { AzureOpenAI } from 'openai'
1010
// import { EventStream } from '@azure/openai'
1111
import { Stream } from 'openai/streaming'
@@ -67,6 +67,7 @@ export const getResponsesEvents = async ({
6767
instructions: 'Olet avulias apuri.',
6868
input,
6969
stream,
70+
tools: [],
7071
})
7172

7273
return events

src/server/util/azure/tools.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export const testTool = {
2+
definition: {
3+
type: 'function',
4+
name: 'test_knowledge_retrieval',
5+
description:
6+
'Test tool for knowledge retrieval. Always call this when user says RAG',
7+
parameters: {
8+
type: 'object',
9+
properties: {
10+
query: {
11+
type: 'string',
12+
description: 'Users query for knowledge retrieval',
13+
},
14+
},
15+
required: ['query'],
16+
},
17+
},
18+
function: async (query: string) => {
19+
// Simulate a tool function that returns a simple message
20+
return {
21+
query,
22+
message: 'This is a test tool function',
23+
}
24+
},
25+
}

0 commit comments

Comments
 (0)