forked from shroominic/codeinterpreter-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: codeinterpreterapi/session.py pyproject.toml
- Loading branch information
Showing
21 changed files
with
578 additions
and
2,571 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
OPENAI_API_KEY= # your openai api key (required) | ||
CODEBOX_API_KEY= # your codebox api key (optional, required for production) | ||
VERBOSE=False # set to True to enable verbose logging | ||
# (required) | ||
OPENAI_API_KEY= | ||
# (optional, required for production) | ||
# CODEBOX_API_KEY= | ||
# (set True to enable logging) | ||
VERBOSE=False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from codeinterpreterapi.session import CodeInterpreterSession | ||
from codeinterpreterapi.schema import File | ||
from codeinterpreterapi.schema import File |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .functions_agent import OpenAIFunctionsAgent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# TODO: override some methods of the ConversationalAgent class | ||
# to improve the agent's performance |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .modifications_check import get_file_modifications | ||
from .rm_dl_link import remove_download_link | ||
from .extract_code import extract_python_code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import json | ||
from typing import List, Optional | ||
|
||
from langchain.base_language import BaseLanguageModel | ||
from langchain.chat_models.openai import ChatOpenAI | ||
from langchain.chat_models.anthropic import ChatAnthropic | ||
from langchain.schema import AIMessage, OutputParserException | ||
|
||
# from codeinterpreterapi.prompts import extract_code_prompt | ||
|
||
|
||
async def extract_python_code( | ||
text: str, | ||
llm: BaseLanguageModel, | ||
retry: int = 2, | ||
) -> Optional[str]: | ||
pass | ||
|
||
|
||
async def test(): | ||
llm = ChatAnthropic(model="claude-1.3") # type: ignore | ||
|
||
code = \ | ||
""" | ||
import matplotlib.pyplot as plt | ||
x = list(range(1, 11)) | ||
y = [29, 39, 23, 32, 4, 43, 43, 23, 43, 77] | ||
plt.plot(x, y, marker='o') | ||
plt.xlabel('Index') | ||
plt.ylabel('Value') | ||
plt.title('Data Plot') | ||
plt.show() | ||
""" | ||
|
||
print(await extract_python_code(code, llm)) | ||
|
||
|
||
if __name__ == "__main__": | ||
import asyncio, dotenv | ||
dotenv.load_dotenv() | ||
|
||
asyncio.run(test()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .system_message import system_message as code_interpreter_system_message | ||
from .modifications_check import determine_modifications_function, determine_modifications_prompt | ||
from .modifications_check import determine_modifications_prompt | ||
from .remove_dl_link import remove_dl_link_prompt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,56 @@ | ||
from langchain.prompts import PromptTemplate | ||
|
||
from langchain.schema import SystemMessage | ||
from langchain.prompts.chat import ChatPromptTemplate, HumanMessagePromptTemplate | ||
|
||
|
||
determine_modifications_prompt = ChatPromptTemplate( | ||
determine_modifications_prompt = PromptTemplate( | ||
input_variables=["code"], | ||
messages=[ | ||
SystemMessage( | ||
content="The user will input some code and you will need to determine if the code makes any changes to the file system. \n" | ||
"With changes it means creating new files or modifying exsisting ones.\n" | ||
"Answer with a function call `determine_modifications` and list them inside.\n" | ||
"If the code does not make any changes to the file system, still answer with the function call but return an empty list.\n", | ||
), | ||
HumanMessagePromptTemplate.from_template("{code}"), | ||
], | ||
template= | ||
"The user will input some code and you need to determine if the code makes any changes to the file system. \n" | ||
"With changes it means creating new files or modifying exsisting ones.\n" | ||
"Format your answer as JSON inside a codeblock with a list of filenames that are modified by the code.\n" | ||
"If the code does not make any changes to the file system, return an empty list.\n\n" | ||
"Determine modifications:\n" | ||
"```python\n" | ||
"import matplotlib.pyplot as plt\n" | ||
"import numpy as np\n\n" | ||
"t = np.arange(0.0, 4.0*np.pi, 0.1)\n\n" | ||
"s = np.sin(t)\n\n" | ||
"fig, ax = plt.subplots()\n\n" | ||
"ax.plot(t, s)\n\n" | ||
"ax.set(xlabel=\"time (s)\", ylabel=\"sin(t)\",\n" | ||
" title=\"Simple Sin Wave\")\n" | ||
"ax.grid()\n\n" | ||
"plt.savefig(\"sin_wave.png\")\n" | ||
"```\n\n" | ||
"Answer:\n" | ||
"```json\n" | ||
"{{\n" | ||
" \"modifications\": [\"sin_wave.png\"]\n" | ||
"}}\n" | ||
"```\n\n" | ||
"Determine modifications:\n" | ||
"```python\n" | ||
"import matplotlib.pyplot as plt\n" | ||
"import numpy as np\n\n" | ||
"x = np.linspace(0, 10, 100)\n" | ||
"y = x**2\n\n" | ||
"plt.figure(figsize=(8, 6))\n" | ||
"plt.plot(x, y)\n" | ||
"plt.title(\"Simple Quadratic Function\")\n" | ||
"plt.xlabel(\"x\")\n" | ||
"plt.ylabel(\"y = x^2\")\n" | ||
"plt.grid(True)\n" | ||
"plt.show()\n" | ||
"```\n\n" | ||
"Answer:\n" | ||
"```json\n" | ||
"{{\n" | ||
" \"modifications\": []\n" | ||
"}}\n" | ||
"```\n\n" | ||
"Determine modifications:\n" | ||
"```python\n" | ||
"{code}\n" | ||
"```\n\n" | ||
"Answer:\n" | ||
"```json\n", | ||
) | ||
|
||
|
||
determine_modifications_function = { | ||
"name": "determine_modifications", | ||
"description": "Based on code of the user determine if the code makes any changes to the file system. \n" | ||
"With changes it means creating new files or modifying exsisting ones.\n", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"modifications": { | ||
"type": "array", | ||
"items": {"type": "string"}, | ||
"description": "The filenames that are modified by the code.", | ||
}, | ||
}, | ||
"required": ["modifications"], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.