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: Add support for Google Gemini #115

Merged
merged 4 commits into from
Dec 19, 2023
Merged

feat: Add support for Google Gemini #115

merged 4 commits into from
Dec 19, 2023

Conversation

LyuLumos
Copy link
Contributor

Description

Add support for Google Gemini Pro API. Link

Linked Issues

None.

Additional context

There are a few points to note:

  • Google Gemini currently does not support Chinese.
  • Gemini doesn't do text chat as well as gpt-3.5-turbo based on my test.
  • The current Gemini API is not perfect and may be modified in the future.

Copy link

netlify bot commented Dec 15, 2023

Deploy Preview for chatgpt-demo-v2 failed.

Name Link
🔨 Latest commit 29f4521
🔍 Latest deploy log https://app.netlify.com/sites/chatgpt-demo-v2/deploys/6580a54c72454800094405be

@LyuLumos LyuLumos changed the title Add support for Google Gemini feat: Add support for Google Gemini Dec 15, 2023
@ddiu8081
Copy link
Member

I'll try it and possibly suggest some changes, thanks for contributing!

@ddiu8081 ddiu8081 self-assigned this Dec 17, 2023
method: 'POST',
body: JSON.stringify({ ...body }),
}
return fetch(`https://generativelanguage.googleapis.com/v1beta3/models/text-bison-001:generateText?key=${apiKey}`, initOptions);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might want to use models/gemini-pro instead of models/text-bison-001?

See https://ai.google.dev/models and curl:

curl https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateContent?key=$API_KEY \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{ "contents":[
      { "parts":[{"text": "Write a story about a magic backpack"}]}
    ]
}'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My apologies. This URL points to PaLM2 instead of Gemini Pro, I'll fix it ASAP

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for my mistake of using PaLM2 as the Gemini API.
I take those words back:

  • Google Gemini currently does not support Chinese. It does support Chinese. API Doc.
  • Also Gemini API has decent dialog capabilities.

Description

  • Remove the PaLM2 model because it've become a legacy. Now users can select gemini-pro for a chat.
  • Modified the process of using the Gemini API conversation.

Additional context

  • It looks like the number of lists passed in must be odd, not even, for multi-round conversations. Another Repo Issue. The corresponding code is in the src/logics/conversation.ts
  • The Gemini api also supports passing in parameters such as temperature, topk, etc.. I will add them in the future.

@ddiu8081
Copy link
Member

ddiu8081 commented Dec 18, 2023

Thanks! I've made a few changes, mainly migrating the logic of translating the OpenAI message structure to Google Gemini inside the provider, leaving the Message type unchanged.

I think some things can be done in the short term, including passing parameters and supporting stream output, but it's fully functional for now. I will merge it if there are no more problems.

@ddiu8081 ddiu8081 merged commit fbd4fb2 into anse-app:main Dec 19, 2023
1 of 5 checks passed
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.

None yet

2 participants