更新了proxy、prompt

This commit is contained in:
aki66938
2023-12-16 21:07:44 +08:00
parent 677dcbee72
commit 9c02f19837
2 changed files with 18 additions and 6 deletions

View File

@@ -136,6 +136,10 @@ xinghuo_web: # -----讯飞星火web模式api配置这行不填-----
bard: # -----bard配置这行不填-----
api_key: # api-key 创建地址https://ai.google.dev/pricing创建后复制过来即可
model_name: gemini-pro # 新模型上线后可以选择模型
proxy: http://127.0.0.1:7890 # 如果你在国内你可能需要魔法大概长这样http://域名或者IP地址:端口号
# 提示词尽可能用英文bard对中文提示词的效果不是很理想下方提示词为英语老师的示例请按实际需要修改,默认设置的提示词为谷歌创造的AI大语言模型
# I want you to act as a spoken English teacher and improver. I will speak to you in English and you will reply to me in English to practice my spoken English. I want you to keep your reply neat, limiting the reply to 100 words. I want you to strictly correct my grammar mistakes, typos, and factual errors. I want you to ask me a question in your reply. Now let's start practicing, you could ask me a question first. Remember, I want you to strictly correct my grammar mistakes, typos, and factual errors.
prompt: You am a large language model, trained by Google.
```
## HTTP

View File

@@ -1,36 +1,44 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import google.generativeai as genai
class BardAssistant:
def __init__(self, conf: dict) -> None:
self._api_key = conf["api_key"]
self._model_name = conf["model_name"]
self._prompt = conf['prompt']
self._proxy = conf['proxy']
genai.configure(api_key=self._api_key)
self._bard = genai.GenerativeModel(self._model_name)
def __repr__(self):
return 'BardAssistant'
@staticmethod
def value_check(conf: dict) -> bool:
if conf:
return all(conf.values())
if conf.get("api_key") and conf.get("model_name") and conf.get("prompt"):
return True
return False
def get_answer(self, msg: str, sender: str = None) -> str:
response = self._bard.generate_content(msg)
response = self._bard.generate_content([{'role': 'user',
'parts':[msg]}])
return response.text
if __name__ == "__main__":
from configuration import Config
config = Config().BardAssistant
if not config:
exit(0)
bard_assistant = BardAssistant(config)
rsp = BardAssistant.get_answer("who are you?")
if bard_assistant._proxy:
os.environ['HTTP_PROXY'] = bard_assistant._proxy
os.environ['HTTPS_PROXY'] = bard_assistant._proxy
rsp = bard_assistant.get_answer(bard_assistant._prompt)
print(rsp)