feat: 新增文心一言接口

This commit is contained in:
bmy
2024-06-28 21:34:49 +08:00
parent 066ef112ad
commit e82c254dc4
5 changed files with 368 additions and 112 deletions

View File

@@ -14,7 +14,7 @@ class LLM:
self.model = 'ernie-3.5'
self.prompt = '''你是一个机器人动作规划者,需要把我的话翻译成机器人动作规划并生成对应的 json 结果,机器人工作空间参考右手坐标系。
严格按照下面的描述生成给定格式 json从现在开始你仅仅给我返回 json 数据'''
严格按照下面的描述生成给定格式 json从现在开始你仅仅给我返回 json 数据'''
self.prompt += '''正确的示例如下:
向左移 0.1m, 向左转弯 85 度 [{'func': 'move', 'x': 0, 'y': 0.1},{'func': 'turn','angle': -85}],
向右移 0.2m, 向前 0.1m [{'func': 'move', 'x': 0, 'y': -0.2},{'func': 'move', 'x': 0.1, 'y': 0}],
@@ -22,6 +22,8 @@ class LLM:
原地左转 38 度 [{'func': 'turn','angle': -38}],
蜂鸣器发声 5 秒 [{'func': 'beep', 'time': 5}]
发光或者照亮 5 秒 [{'func': 'light', 'time': 5}]
向右走 30cm照亮 2s [{'func': 'move', 'x': 0, 'y': -0.3}, {'func': 'light', 'time': 2}],
向左移 0.2m, 向后 0.1m [{'func': 'move', 'x': 0, 'y': 0.2},{'func': 'move', 'x': -0.1, 'y': 0}],
'''
self.messages = []
self.resp = None
@@ -47,6 +49,8 @@ if __name__ == "__main__":
lmm_bot = LLM()
while True:
chat = input("输入:")
print(lmm_bot.get_command_json(chat))
resp = lmm_bot.get_command_json(chat).replace(' ', '').replace('\n', '').replace('\t', '')
print(eval(resp[7:-3]))