2 ms·
does your team do usability tests on the apis before launching them? if you got 3-5 developers to try and use one of the sdks to build something, i bet you'd s
by willsmith72 3y ago
does your team do usability tests on the apis before launching them?
if you got 3-5 developers to try and use one of the sdks to build something, i bet you'd see common trends.
e.g. we recently had to update an assistant with new data everyday and get 1 response, and this is what the engineer came up with. probably it could be improved, but this is really ugly
```
const file = await openai.files.create({
file: fs.createReadStream(fileName),
purpose: 'assistants',
})
await openai.beta.assistants.update(assistantId, {
file_ids: [file.id],
})
const { id: threadId } = await openai.beta.threads.create({
messages: [
{
role: 'user',
content:
'Create PostSuggestions from the file. Remember to keep the style fun and engaging, not just regurgitating the headlines. Read the WHOLE article.',
},
],
})
const getSuggestions = async (runIdArg: string) => {
return new Promise<PostSuggestions>(resolve => {
const checkStatus = async () => {
const { status, last_error, required_action } = await openai.beta.threads.runs.retrieve(threadId, runIdArg)
console.log({ status })
if (status === 'requires_action') {
if (required_action?.type === 'submit_tool_outputs') {
required_action?.submit_tool_outputs?.tool_calls?.forEach(async toolOutput => {
const parsed = PostSuggestions.safeParse(JSON.parse(toolOutput.function.arguments))
if (parsed.success) {
await openai.beta.threads.runs.cancel(threadId, runIdArg)
resolve(parsed.data)
} else {
console.error(`failed to parse args from openai to my type (errors=${parsed.error.errors}`)
}
})
} else {
console.error(`requires_action, but not submit_tool_outputs (type=${required_action?.type})`)
}
} else if (status === 'completed') {
throw new Error(`status is completed, but no data. supposed to go to requires_action`)
} else if (status === 'failed') {
throw new Error(`message=${last_error?.message}, code=${last_error?.code}`)
} else {
setTimeout(checkStatus, 500)
}
}
checkStatus()
})
}
const { id: runId } = await openai.beta.threads.runs.create(threadId, {
assistant_id: assistantId,
})
console.time('openai create thread')
const newsSuggestions = await getSuggestions(runId)
console.timeEnd('openai create thread')
```
- willsmith72 3y agojust to add to this, it's not helped by the docs. either they don't exist, or the seo isn't working right. e.g. search term for me "openai assistant service function call node". The first 2 results are community forums, not what i'm looking for. The 3rd is seemingly the official one but doesn't actually answer the question (how to use the assistance service with node and function calling) with an example. The 4th is in python. https://community.openai.com/t/how-does-function-calling-actually-work-for-the-assistants-api/641440 https://community.openai.com/t/how-does-function-calling-act... https://community.openai.com/t/how-assistant-api-function-calling-works-w-o-server-endpoint/500342 https://community.openai.com/t/how-assistant-api-function-ca... https://platform.openai.com/docs/guides/function-calling https://platform.openai.com/docs/guides/function-calling https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/assistant-functions https://learn.microsoft.com/en-us/azure/ai-services/openai/h...
- rattray 3y agoI'm sorry for your experience, and thanks very much for sharing the code snippet - that's helpful! We did indeed code up some sample apps and highlighted this exact concern. We have some helpers planned to make it smoother, which we hope to launch before Assistants GA. For streaming beta, we were focused just on the streaming part of these helpers.