Skip to content

Commit

Permalink
doc: update
Browse files Browse the repository at this point in the history
  • Loading branch information
whybeyoung committed Mar 27, 2024
1 parent 31cc91b commit 8621102
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 34 deletions.
14 changes: 10 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "spark-ai-python"
version = "0.3.6"
version = "0.3.8"
description = "a sdk for iflytek's spark LLM."
authors = ["whybeyoung <ybyang7@iflytek.com>", "mingduan <mingduan@iflytek.com>"]
license = "MIT"
Expand All @@ -12,21 +12,27 @@ packages = [
[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
aiohttp = ">3.3"
fastapi = { extras = ["all"], version = "^0.110.0" }
requests = "*"
nest-asyncio = "^1.6.0"
websocket-client = "^1.7.0"
websockets = "*"
nest_asyncio = "*"
uvicorn = ">=0.26.0"

packaging = "*"
tenacity = "*"
jsonpatch = "*"
llama-index-core = { version = "^0.10.24.post1", optional = true }
uvicorn = { version = ">=0.26.0", optional = true }
fastapi = { extras = ["all"], version = "^0.110.0", optional = true}

[tool.poetry.extras]
llam_index = [
llama_index = [
"llama-index-core"
]
proxy = [
"fastapi",
"uvicorn"
]

[tool.pytest.ini_options]

Expand Down
31 changes: 1 addition & 30 deletions sparkai/frameworks/llama_index/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ def stream_complete(
self, prompt: str, formatted: bool = False, **kwargs: Any
) -> CompletionResponseGen:
spark = self.get_spark(True)
spark_messages = []
for message in messages:
spark_messages.append(SparkChatMessage(content=message.content, role=message.role))
spark_messages = [SparkChatMessage(content=prompt.format(**kwargs), role="user")]

result_q = Queue()
handler = StreamerProcess(result_q)
Expand All @@ -276,30 +274,3 @@ def stream_complete(
)


if __name__ == '__main__':
try:
from dotenv import load_dotenv
except ImportError:
raise RuntimeError(
'Python environment for SPARK AI is not completely set up: required package "python-dotenv" is missing.') from None
load_dotenv()
s = SparkAI(
spark_api_url=os.environ["SPARKAI_URL"],
spark_app_id=os.environ["SPARKAI_APP_ID"],
spark_api_key=os.environ["SPARKAI_API_KEY"],
spark_api_secret=os.environ["SPARKAI_API_SECRET"],
spark_llm_domain=os.environ["SPARKAI_DOMAIN"],
streaming=True,
)
messages = [{'role': 'user',
'content': '作为AutoSpark的创建者角色,当前需要你帮我分析并生成任务,你当前主要目标是:\n1. 帮我写个贪吃蛇python游戏\n\n\n\n\n当前执行任务节点是: `编写贪吃蛇游戏的界面设计`\n\n任务执行历史是:\n`\nTask: 使用ThinkingTool分析贪吃蛇游戏的需求\nResult: Error2: {\'error\': \'Could not parse invalid format: 根据任务节点,我将使用ThinkingTool来分析贪吃蛇游戏的需求。首先,我们需要理解游戏的基本功能和规则。贪吃蛇游戏的主要目标是控制一条蛇在屏幕上移动,吃到食物后蛇会变长,碰到自己的身体或者屏幕边缘则游戏结束。\\n\\n接下来,我们可以使用CodingTool来编写贪吃蛇游戏的代码。首先,我们需要定义以下核心类和方法:\\n\\n1. Snake类:用于表示贪吃蛇的状态,包括蛇的身体、移动方向等。\\n2. Food类:用于表示食物的位置。\\n3. Game类:用于控制游戏的进行,包括初始化游戏、更新蛇的位置、检查碰撞等。\\n4. main函数:用于启动游戏。\\n\\n接下来,我们将这些类和方法的代码写入文件中。\\n\\n最后,我们可以使用WriteTestTool来编写测试用例,确保我们的代码能够正确地运行。测试用例应该包括以下内容:\\n\\n1. 测试游戏是否能正确初始化。\\n2. 测试蛇是否能正确移动。\\n3. 测试蛇是否能正确吃到食物并变长。\\n4. 测试蛇是否能正确碰到自己的身体或屏幕边缘导致游戏结束。 exceptionNot get command from llm response...\'}. \nTask: 编写贪吃蛇游戏的spec文件\nResult: Error2: {\'error\': \'Could not parse invalid format: 根据任务节点,我将使用`WriteSpecTool`来编写贪吃蛇游戏的spec文件。\\n\\n首先,我们需要定义以下核心类和方法:\\n1. Snake类:用于表示贪吃蛇的状态,包括蛇的身体、移动方向等。\\n2. Food类:用于表示食物的位置。\\n3. Game类:用于控制游戏的进行,包括初始化游戏、更新蛇的位置、检查碰撞等。\\n4. main函数:用于启动游戏。\\n\\n接下来,我们将这些类和方法的代码写入文件中。\\n\\n最后,我们可以使用`WriteTestTool`来编写测试用例,确保我们的代码能够正确地运行。测试用例应该包括以下内容:\\n1. 测试游戏是否能正确初始化。\\n2. 测试蛇是否能正确移动。\\n3. 测试蛇是否能正确吃到食物并变长。\\n4. 测试蛇是否能正确碰到自己的身体或屏幕边缘导致游戏结束。 exceptionNot get command from llm response...\'}. \n\n`\n\n根据上述背景信息,你的任务是需要理解当前的任务节点关键信息,创建一个规划,解释为什么要这么做,并且提及一些需要注意的事项,必须从下述TOOLS中挑选一个命令用于下一步执行。\n\nTOOLS:\n1. "ThinkingTool": Intelligent problem-solving assistant that comprehends tasks, identifies key variables, and makes efficient decisions, all while providing detailed, self-driven reasoning for its choices. Do not assume anything, take the details from given data only., args : task_description: "<task_description>",\n2. "WriteSpecTool": A tool to write the spec of a program., args : task_description: "<task_description>",spec_file_name: "<spec_file_name>",\n3. "CodingTool": You will get instructions for code to write. You will write a very long answer. Make sure that every detail of the architecture is, in the end, implemented as code. Think step by step and reason yourself to the right decisions to make sure we get it right. You will first lay out the names of the core classes, functions, methods that will be necessary, as well as a quick comment on their purpose. Then you will output the content of each file including ALL code., args : code_description: "<code_description>",\n4. "WriteTestTool": 您是一位超级聪明的开发人员,使用测试驱动开发根据规范编写测试。\n请根据上述规范生成测试。测试应该尽可能简单, 但仍然涵盖了所有功能。\n将它们写入文件中, args : test_description: "<test_description>",test_file_name: "<test_file_name>",\n\n\n\n约束条件:\n1. 请注意返回的命令名称和参数不要被引号包裹\n2. 命令名称必须是TOOLS中的已知的\n3. 你只能生成一个待执行命令名称及其对应参数\n4. 你生成的命令必须是用来解决 `编写贪吃蛇游戏的界面设计`\n\n在之后的每次回答中,你必须严格遵从上述约束条件并按照如下JsonSchema约束返回响应:\n\n{\n "$schema": "http://json-schema.org/draft-07/schema#",\n "type": "object",\n "properties": {\n "thoughts": {\n "type": "object",\n "properties": {\n "reasoning": {\n "type": "string",\n "description": "short reasoning",\n }\n },\n "required": ["reasoning"]\n },\n "tool": {\n "type": "object",\n "properties": {\n "name": {\n "type": "string",\n "description": "tool name",\n },\n "args": {\n "type": "object",\n "description": "tool arguments",\n }\n },\n "required": ["name", "args"]\n }\n }\n}'}]

messages = [SparkChatMessage(
role="user",
content=messages[0]['content']

)]
#g = s.chat(messages)
for i in s.stream_chat(messages):
print(i)
#print(g)

0 comments on commit 8621102

Please sign in to comment.