codeinterpreter-codebox icon indicating copy to clipboard operation
codeinterpreter-codebox copied to clipboard

请问这个代码function call部分是否存在问题

Open abc-w opened this issue 1 year ago • 4 comments

根据代码逻辑,根据提示词大模型的答案只是生成code,与function call无关,function call run_code这部分一直不会执行,正确的逻辑应该是提取大模型生成的code,作为参数传入run_code?

/bin/python3 /home/pingchuan/codeinterpreter-codebox/examples/client/codeinterpreter_session.py Internal Server Error 500 Message(content='As an AI language model, I don't have access to the uploaded file in the directory. However, you can use the following code to count the number of columns in the CSV file:\n\n\nimport pandas as pd\n\ndf = pd.read_csv(\'/codebox/test_data.csv\')\nnum_columns = len(df.columns)\n\nprint(f"The CSV file has {num_columns} columns.")\n\n\nPlease copy and paste this code into the run_code function to execute it on your local machine.', role='assistant', tool_calls=None, function_call=None) close error Traceback (most recent call last): File "/home/pingchuan/codeinterpreter-codebox/examples/client/codeinterpreter_session.py", line 239, in session.chat('上传的文件中有多少列数据') File "/home/pingchuan/codeinterpreter-codebox/examples/client/codeinterpreter_session.py", line 205, in chat if "function_call" in completion.keys() and 'run_code' == completion['function_call']['name']: File "/home/pingchuan/.local/lib/python3.8/site-packages/pydantic/main.py", line 828, in getattr raise AttributeError(f'{type(self).name!r} object has no attribute {item!r}') AttributeError: 'Message' object has no attribute 'keys'

abc-w avatar Aug 12 '24 07:08 abc-w

应该是langchain版本的问题。 开发时用的是旧版本。新版本可能改了请求返回的结构体了。 可以尝试改下 把if "function_call" in completion.keys() and 'run_code' == completion['function_call']['name']:

改成 if completion.function_call and completion.function_call.name == 'run_code'

zhangzhejian avatar Aug 14 '24 08:08 zhangzhejian

应该是langchain版本的问题。 开发时用的是旧版本。新版本可能改了请求返回的结构体了。 可以尝试改下 把if "function_call" in completion.keys() and 'run_code' == completion['function_call']['name']:

改成 if completion.function_call and completion.function_call.name == 'run_code'

这块感觉有点疑问,传入run_code到function call里让大模型生成代码,不是应该先让大模型根据query生成代码,然后再将代码作为参数传入run_code里执行?

abc-w avatar Aug 14 '24 09:08 abc-w

这部分是以function_call的逻辑实现了agent的部分。当llm判断需要执行代码的时候,会去调用'run_code'方法,入参是代码块。

zhangzhejian avatar Aug 14 '24 09:08 zhangzhejian

def download_files(self, filenames: List[str]): if isinstance(filenames, str): filenames = ast.literal_eval(filenames)

url = self.domain + '/api/v1/jupyter/download'

session_key = {"session_id": self.session_id, "language": "JUPYTER"}

print(f"file paths: {filenames}")

headers = {'Content-Type': 'application/json', 'Accept': 'text/plain'}

data = {
    "session_key": session_key,
    "filenames": filenames,
}

print(f"Data sent: {data}")

try:
    response = requests.post(url, json=data, headers=headers)
    response.raise_for_status()  # This will raise an HTTPError if the HTTP request returned an unsuccessful status code.
except requests.exceptions.HTTPError as e:
    print(f"HTTP error occurred: {e}")
except Exception as e:
    print(f"Other error occurred: {e}")
else:
    print(f"Response received: {response.status_code}")
    if response.status_code == 200:
        for file_data in response.json():
            filename = file_data["name"]
            content = file_data["content"]
            with open(filename, "w", encoding="utf-8") as f:
                f.write(content)
            print(f"Downloaded {filename}")
    else:
        print(f"Unexpected error: {response.status_code}")
        print(response.text)
return response.text

请教一下,这边我写了个client下载文件,不知道为什么请求会报500 Error: 500 Internal Server Error

abc-w avatar Aug 20 '24 12:08 abc-w