Skip to content

Commit

Permalink
fix: all in one
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu007 committed May 14, 2024
1 parent 2f861bb commit 3610771
Show file tree
Hide file tree
Showing 34 changed files with 867 additions and 348 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "llm_docker_setting_pub"]
path = llm_docker_setting_pub
url = https://github.com/nobu007/llm_docker_setting_pub.git
[submodule "GuiAgentLoopCore"]
path = GuiAgentLoopCore
url = https://github.com/nobu007/GuiAgentLoopCore.git
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repos:
# Using this mirror lets us use mypyc-compiled black, which is 2x faster
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.10.1
hooks:
- id: black
# It is recommended to specify the latest version of Python
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.11
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
1 change: 1 addition & 0 deletions GuiAgentLoopCore
Submodule GuiAgentLoopCore added at f92616
25 changes: 0 additions & 25 deletions envsetup.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,2 @@
# AUTO DEV SETUP

# check if rye is installed
if ! command -v rye &>/dev/null; then
echo "rye could not be found: installing now ..."
curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash
echo "Check the rye docs for more info: https://rye-up.com/"
fi

export PATH="$HOME/.rye/shims:$PATH"

cd /app
source "$HOME/.rye/env"
echo 'source "$HOME/.rye/env"' >> ~/.bashrc
echo 'source "$HOME/.rye/env"' >> ~/.profile


echo "SYNC: setup .venv"
rye sync

rye add pytest pre-commit

echo "ACTIVATE: activate .venv"
source .venv/bin/activate

echo "SETUP: install pre-commit hooks"
pre-commit install
6 changes: 2 additions & 4 deletions examples/anthropic_claude.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from codeinterpreterapi import CodeInterpreterSession

with CodeInterpreterSession(model="claude-2") as session:
result = session.generate_response(
"Plot the nvidea stock vs microsoft stock over the last 6 months."
)
with CodeInterpreterSession(model="claude-3-haiku-20240307") as session:
result = session.generate_response("Plot the nvidea stock vs microsoft stock over the last 6 months.")
result.show()
7 changes: 1 addition & 6 deletions examples/chat_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

settings.MODEL = "gpt-4"

print(
"AI: Hello, I am the "
"code interpreter agent.\n"
"Ask me todo something and "
"I will use python to do it!\n"
)
print("AI: Hello, I am the " "code interpreter agent.\n" "Ask me todo something and " "I will use python to do it!\n")

with CodeInterpreterSession() as session:
while True:
Expand Down
7 changes: 5 additions & 2 deletions examples/chat_history_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
from codeinterpreterapi import CodeInterpreterSession # noqa: E402


def main() -> None:
def main(is_local=True) -> None:
session_id = None

session = CodeInterpreterSession()
session.start()
if is_local:
session.start_local()
else:
session.start()

print("Session ID:", session.session_id)
session_id = session.session_id
Expand Down
3 changes: 2 additions & 1 deletion examples/frontend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import sys

import streamlit as st

from codeinterpreterapi import File
from utils import get_images # type: ignore
from codeinterpreterapi.config import settings

# Page configuration
st.set_page_config(layout="wide")
Expand Down
28 changes: 11 additions & 17 deletions examples/frontend/chainlitui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chainlit as cl # type: ignore

from codeinterpreterapi import CodeInterpreterSession
from codeinterpreterapi import File as CIFile

Expand All @@ -11,37 +12,32 @@ async def on_action(action: cl.Action) -> None:

# Wait for the user to upload a file
while files is None:
files = await cl.AskFileMessage(
content="Please upload a text file to begin!", accept=["text/csv"]
).send()
files = await cl.AskFileMessage(content="Please upload a text file to begin!", accept=["text/csv"]).send()
# Decode the file
text_file = files[0]
text = text_file.content.decode("utf-8")

UPLOADED_FILES.append(text_file)

# Let the user know that the system is ready
await cl.Message(
content=f"`{text_file.name}` uploaded, it contains {len(text)} characters!"
).send()
await cl.Message(content=f"`{text_file.name}` uploaded, it contains {len(text)} characters!").send()
await action.remove()


@cl.on_chat_start
async def start_chat() -> None:
actions = [
cl.Action(name="upload_file", value="example_value", description="Upload file")
]
actions = [cl.Action(name="upload_file", value="example_value", description="Upload file")]

await cl.Message(
content="Hello, How can I assist you today", actions=actions
).send()
await cl.Message(content="Hello, How can I assist you today", actions=actions).send()


@cl.on_message
async def run_conversation(user_message: str) -> None:
async def run_conversation(user_message: str, is_local=True) -> None:
session = CodeInterpreterSession()
await session.astart()
if is_local:
await session.astart_local()
else:
await session.astart()

files = [CIFile(name=it.name, content=it.content) for it in UPLOADED_FILES]

Expand All @@ -54,9 +50,7 @@ async def run_conversation(user_message: str) -> None:
)
for file in response.files
]
actions = [
cl.Action(name="upload_file", value="example_value", description="Upload file")
]
actions = [cl.Action(name="upload_file", value="example_value", description="Upload file")]
await cl.Message(
content=response.content,
elements=elements,
Expand Down
3 changes: 2 additions & 1 deletion examples/frontend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Optional

import streamlit as st

from codeinterpreterapi import CodeInterpreterSession


Expand All @@ -21,7 +22,7 @@ async def get_images(prompt: str, files: Optional[list] = None) -> list:
with st.chat_message("user"): # type: ignore
st.write(prompt)
with st.spinner():
async with CodeInterpreterSession(model="gpt-3.5-turbo") as session:
async with CodeInterpreterSession(model="claude-3-haiku-20240307") as session:
response = await session.agenerate_response(prompt, files=files)

with st.chat_message("assistant"): # type: ignore
Expand Down
4 changes: 1 addition & 3 deletions examples/plot_sin_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

async def main() -> None:
async with CodeInterpreterSession() as session:
response = await session.agenerate_response(
"Plot a sin wave and show it to me."
)
response = await session.agenerate_response("Plot a sin wave and show it to me.")
response.show()


Expand Down
4 changes: 1 addition & 3 deletions examples/show_bitcoin_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ def main() -> None:
with CodeInterpreterSession(local=True) as session:
currentdate = datetime.now().strftime("%Y-%m-%d")

response = session.generate_response(
f"Plot the bitcoin chart of 2023 YTD (today is {currentdate})"
)
response = session.generate_response(f"Plot the bitcoin chart of 2023 YTD (today is {currentdate})")

# prints the text and shows the image
response.show()
Expand Down
12 changes: 5 additions & 7 deletions examples/use_additional_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
so it can download the bitcoin chart from yahoo finance
and plot it for you
"""

import csv
import io
from typing import Any

from codeinterpreterapi import CodeInterpreterSession
from langchain_core.tools import BaseTool

from codeinterpreterapi import CodeInterpreterSession


class ExampleKnowledgeBaseTool(BaseTool):
name: str = "salary_database"
Expand All @@ -31,12 +33,8 @@ async def _arun(self, *args: Any, **kwargs: Any) -> Any:


async def main() -> None:
async with CodeInterpreterSession(
additional_tools=[ExampleKnowledgeBaseTool()]
) as session:
response = await session.agenerate_response(
"Plot chart of company employee salaries"
)
async with CodeInterpreterSession(additional_tools=[ExampleKnowledgeBaseTool()]) as session:
response = await session.agenerate_response("Plot chart of company employee salaries")

response.show()

Expand Down
Loading

0 comments on commit 3610771

Please sign in to comment.