XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Update README.md

Added comments to clarify how to set the Hugging Face token as the API key and also improved the comments for code readability

92a31d82
Aryan4884 <116114086+Aryan4884@users.noreply.github.com>
提交于

代码差异

1 个文件 +10 -7
Modified README.md +10 -7
@@ -331,9 +331,12 @@ python -m g4f.api
331 331 ```py
332 332 import openai
333 333
334 openai.api_key = " Leave Empty if you don't use embeddings, otherwise your Hugging Face token"
335 openai.api_base = "http://localhost:1337/v1"
334 # Set your Hugging Face token as the API key if you use embeddings
335 # If you don't use embeddings, leave it empty
336 openai.api_key = "YOUR_HUGGING_FACE_TOKEN" # Replace with your actual token
336 337
338 # Set the API base URL if needed, e.g., for a local development environment
339 openai.api_base = "http://localhost:1337/v1"
337 340
338 341 def main():
339 342 chat_completion = openai.ChatCompletion.create(
@@ -343,18 +346,18 @@ def main():
343 346 )
344 347
345 348 if isinstance(chat_completion, dict):
346 # not stream
349 # Not streaming
347 350 print(chat_completion.choices[0].message.content)
348 351 else:
349 # stream
352 # Streaming
350 353 for token in chat_completion:
351 354 content = token["choices"][0]["delta"].get("content")
352 if content != None:
355 if content is not None:
353 356 print(content, end="", flush=True)
354 357
355
356 if __name__ == "__main__":
358 if __name__ == "__main":
357 359 main()
360
358 361 ```
359 362
360 363 ## Models