Skip to content

Commit

Permalink
pre-commit all files
Browse files Browse the repository at this point in the history
  • Loading branch information
warching committed Aug 7, 2023
1 parent abc5993 commit cf641fd
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ VERBOSE=False
# OPENAI_API_TYPE=azure
# OPENAI_API_VERSION=2023-07-01-preview
# OPENAI_API_BASE=
# DEPLOYMENT_NAME=
# DEPLOYMENT_NAME=
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ To configure OpenAI and Azure OpenAI, ensure that you set the appropriate enviro

For OpenAI, set the OPENAI_API_KEY environment variable:
```
export OPENAI_API_KEY=your_openai_api_key
export OPENAI_API_KEY=your_openai_api_key
```

For Azure OpenAI, set the following environment variables:
```
export OPENAI_API_TYPE=azure
export OPENAI_API_VERSION=your_api_version
export OPENAI_API_BASE=your_api_base
export OPENAI_API_KEY=your_azure_openai_api_key
export DEPLOYMENT_NAME=your_deployment_name
export OPENAI_API_TYPE=azure
export OPENAI_API_VERSION=your_api_version
export OPENAI_API_BASE=your_api_base
export OPENAI_API_KEY=your_azure_openai_api_key
export DEPLOYMENT_NAME=your_deployment_name
```

Remember to replace the placeholders with your actual API keys and other required information.

```python
Expand Down
23 changes: 16 additions & 7 deletions codeinterpreterapi/agents/functions_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@
from langchain.callbacks.base import BaseCallbackManager
from langchain.callbacks.manager import Callbacks
from langchain.chat_models.openai import ChatOpenAI
from langchain.prompts.chat import (BaseMessagePromptTemplate,
ChatPromptTemplate,
HumanMessagePromptTemplate,
MessagesPlaceholder)
from langchain.schema import (AgentAction, AgentFinish, AIMessage, BaseMessage,
BasePromptTemplate, FunctionMessage,
OutputParserException, SystemMessage)
from langchain.prompts.chat import (
BaseMessagePromptTemplate,
ChatPromptTemplate,
HumanMessagePromptTemplate,
MessagesPlaceholder,
)
from langchain.schema import (
AgentAction,
AgentFinish,
AIMessage,
BaseMessage,
BasePromptTemplate,
FunctionMessage,
OutputParserException,
SystemMessage,
)
from langchain.tools import BaseTool
from langchain.tools.convert_to_openai import format_tool_to_openai_function
from pydantic import root_validator
Expand Down
3 changes: 1 addition & 2 deletions codeinterpreterapi/prompts/remove_dl_link.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from langchain.prompts.chat import (ChatPromptTemplate,
HumanMessagePromptTemplate)
from langchain.prompts.chat import ChatPromptTemplate, HumanMessagePromptTemplate
from langchain.schema import AIMessage, HumanMessage, SystemMessage

remove_dl_link_prompt = ChatPromptTemplate(
Expand Down
28 changes: 19 additions & 9 deletions codeinterpreterapi/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@
from langchain.tools import BaseTool, StructuredTool

from codeinterpreterapi.agents import OpenAIFunctionsAgent
from codeinterpreterapi.chains import (get_file_modifications,
remove_download_link)
from codeinterpreterapi.chains import get_file_modifications, remove_download_link
from codeinterpreterapi.config import settings
from codeinterpreterapi.prompts import code_interpreter_system_message
from codeinterpreterapi.schema import (CodeInput, CodeInterpreterResponse,
File, UserRequest)
from codeinterpreterapi.utils import (CodeAgentOutputParser,
CodeCallbackHandler,
CodeChatAgentOutputParser)
from codeinterpreterapi.schema import (
CodeInput,
CodeInterpreterResponse,
File,
UserRequest,
)
from codeinterpreterapi.utils import (
CodeAgentOutputParser,
CodeCallbackHandler,
CodeChatAgentOutputParser,
)


class CodeInterpreterSession:
Expand Down Expand Up @@ -86,15 +91,20 @@ def _choose_llm(
openai_api_base = getenv("OPENAI_API_BASE")
deployment_name = getenv("DEPLOYMENT_NAME")
openapi_type = getenv("OPENAI_API_TYPE")
if openapi_type == "azure" and openai_api_version and openai_api_base and deployment_name:
if (
openapi_type == "azure"
and openai_api_version
and openai_api_base
and deployment_name
):
return AzureChatOpenAI(
temperature=0.03,
openai_api_base=openai_api_base,
openai_api_version=openai_api_version,
deployment_name=deployment_name,
openai_api_key=openai_api_key,
max_retries=3,
request_timeout=60*3
request_timeout=60 * 3,
)
else:
return ChatOpenAI(
Expand Down
3 changes: 1 addition & 2 deletions codeinterpreterapi/utils/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ def _type(self) -> str:

class CodeChatAgentOutputParser(AgentOutputParser):
def get_format_instructions(self) -> str:
from langchain.agents.conversational_chat.prompt import \
FORMAT_INSTRUCTIONS
from langchain.agents.conversational_chat.prompt import FORMAT_INSTRUCTIONS

return FORMAT_INSTRUCTIONS

Expand Down

0 comments on commit cf641fd

Please sign in to comment.