@@ -136,6 +136,10 @@ xinghuo_web: # -----讯飞星火web模式api配置这行不填-----
|
|||||||
bard: # -----bard配置这行不填-----
|
bard: # -----bard配置这行不填-----
|
||||||
api_key: # api-key 创建地址:https://ai.google.dev/pricing,创建后复制过来即可
|
api_key: # api-key 创建地址:https://ai.google.dev/pricing,创建后复制过来即可
|
||||||
model_name: gemini-pro # 新模型上线后可以选择模型
|
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
|
## HTTP
|
||||||
|
|||||||
@@ -1,36 +1,44 @@
|
|||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
import os
|
||||||
import google.generativeai as genai
|
import google.generativeai as genai
|
||||||
|
|
||||||
|
|
||||||
class BardAssistant:
|
class BardAssistant:
|
||||||
def __init__(self, conf: dict) -> None:
|
def __init__(self, conf: dict) -> None:
|
||||||
self._api_key = conf["api_key"]
|
self._api_key = conf["api_key"]
|
||||||
self._model_name = conf["model_name"]
|
self._model_name = conf["model_name"]
|
||||||
|
self._prompt = conf['prompt']
|
||||||
|
self._proxy = conf['proxy']
|
||||||
|
|
||||||
genai.configure(api_key=self._api_key)
|
genai.configure(api_key=self._api_key)
|
||||||
self._bard = genai.GenerativeModel(self._model_name)
|
self._bard = genai.GenerativeModel(self._model_name)
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return 'BardAssistant'
|
return 'BardAssistant'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def value_check(conf: dict) -> bool:
|
def value_check(conf: dict) -> bool:
|
||||||
if conf:
|
if conf:
|
||||||
return all(conf.values())
|
if conf.get("api_key") and conf.get("model_name") and conf.get("prompt"):
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_answer(self, msg: str, sender: str = None) -> str:
|
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
|
return response.text
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from configuration import Config
|
from configuration import Config
|
||||||
config = Config().BardAssistant
|
config = Config().BardAssistant
|
||||||
if not config:
|
if not config:
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
bard_assistant = BardAssistant(config)
|
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)
|
print(rsp)
|
||||||
|
|||||||
@@ -73,3 +73,7 @@ xinghuo_web: # -----讯飞星火web模式api配置这行不填 抓取方式详
|
|||||||
bard: # -----bard配置这行不填-----
|
bard: # -----bard配置这行不填-----
|
||||||
api_key: # api-key 创建地址:https://ai.google.dev/pricing?hl=en,创建后复制过来即可
|
api_key: # api-key 创建地址:https://ai.google.dev/pricing?hl=en,创建后复制过来即可
|
||||||
model_name: gemini-pro # 新模型上线后可以选择模型
|
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.
|
||||||
|
|||||||
Reference in New Issue
Block a user