anse icon indicating copy to clipboard operation
anse copied to clipboard

How to set the default API key

Open editionserver opened this issue 1 year ago • 1 comments

Describe the feature

how to set the default API key

Additional context

I don't want people to enter the API, I added it by default so that the openai API is recognized automatically and everyone can chat.

Participation

  • [ ] I am willing to submit a pull request for this feature.

editionserver avatar Jul 11 '23 21:07 editionserver

This issue is similar to https://github.com/anse-app/anse/issues/1.

This project does not support setting environment variables now. However, if your project (source code) is not public, you can try:

// src/providers/openai/api.ts
export const fetchChatCompletion = async(payload: OpenAIFetchPayload) => {
   if (!payload.apiKey) {
    payload.apiKey = 'sk-xxx'
  }
  const initOptions = {
    // same
  }
  return fetch(`${payload.baseUrl}/v1/chat/completions`, initOptions)
}

It will not display your key in web. And if the user enters his key, it will be used first.

LyuLumos avatar Jul 12 '23 14:07 LyuLumos