Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(functions): add chat completion functions #7

Merged
merged 2 commits into from
Jun 19, 2023

Conversation

robswei
Copy link
Contributor

@robswei robswei commented Jun 17, 2023

Added chat completion functions from latest openai-node v3.3.0

Ref: https://platform.openai.com/docs/guides/gpt/function-calling

@Zakinator123
Copy link

@rtweine2 Just curious, how did you go about generating the new code? Was trying to do the same, and found that the OpenAI OpenAPI generator was generating code that was structured differently than the code in this repo when I changed the OpenAPI generator to use typescript-fetch, and there's no instructions in this repo on how to go about generating new code from the latest OpenAPI spec that OpenAI puts out..

@henrycunh
Copy link

henrycunh commented Jun 18, 2023

published this PR to openai-edge-fns npm package if anyone needs this ASAP

@dan-kwiat
Copy link
Owner

Thanks @rtweine2 !

@dan-kwiat dan-kwiat merged commit 4e15475 into dan-kwiat:main Jun 19, 2023
@swyxio
Copy link

swyxio commented Jun 22, 2023

@Zakinator123 this isnt a complete answer but i think you can just pull it from openai-node openai/openai-node@b7cbca5

@abaybektursun
Copy link

New to react and next.js. How would I extract the function call here? res does not seem to have it

  const res = await openai.createChatCompletion({
    model: 'gpt-4',
    messages: messagesWithSystemPrompt,
    temperature: 0.0,
    stream: true
  })

  // log res
  console.log(res)
  
const stream = OpenAIStream(res, {
    async onCompletion(completion) {
      const title = json.messages[0].content.substring(0, 100)
      const id = json.id ?? nanoid()
      const createdAt = Date.now()
      const path = `/chat/${id}`
      const payload = {
        id,
        title,
        userId,
        createdAt,
        path,
        messages: [
          ...messages,
          {
            content: completion,
            role: 'assistant'
          }
        ]
      }
      await kv.hmset(`chat:${id}`, payload)
      await kv.zadd(`user:chat:${userId}`, {
        score: createdAt,
        member: `chat:${id}`
      })
    }
  })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants