shroominic / codeinterpreter-api

👾 Open source implementation of the ChatGPT Code Interpreter
https://discord.gg/Vaq25XJvvW
MIT License
3.76k stars 400 forks source link

Interpreter Error with Multi-line Code Strings due to String Literal Formatting #135

Closed erickfm closed 11 months ago

erickfm commented 11 months ago

I'm getting a SyntaxError: unterminated string literal from time to time on various runs. It only affects multi-line code strings and sometimes it resolves but other times it causes the interpreter to hit the iteration limit. The query causing the issue can vary. I can coerce this bug out with some additional guidelines in my request like "don't use a line break at the start of a code string" but it isn't ideal.

Here's the code causing the error:

from codeinterpreterapi import CodeInterpreterSession, schema, settings

settings.TEMPERATURE = 0
files = [schema.File.from_path('synthetic_cancer_patient_data.csv')]

def chat(prompt):
    with CodeInterpreterSession(model='gpt-4') as session:
      print('session:', session)
      response = session.generate_response(
          prompt,
          files
      )
      for file in response.files:
          file.show_image()
    return response.content, response

response, r = chat(prompt)
print(response)

Here's a screenshot of the Error in LangSmith:

Screenshot 2023-10-17 at 2 04 29 AM
erickfm commented 11 months ago

Here's the output after the changes from https://github.com/shroominic/codeinterpreter-api/pull/136

Screenshot 2023-10-17 at 3 57 13 AM

dataset is synthetic data