Skip to content

Commit

Permalink
Updating files
Browse files Browse the repository at this point in the history
  • Loading branch information
hinthornw committed Sep 19, 2024
1 parent 9e8bc1b commit 75af61f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 36 deletions.
1 change: 0 additions & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@ jobs:
TAVILY_API_KEY: ${{ secrets.TAVILY_API_KEY }}
LANGSMITH_API_KEY: ${{ secrets.LANGSMITH_API_KEY }}
LANGSMITH_TRACING: true
LANGSMITH_TEST_CACHE: tests/casettes
run: |
uv run pytest tests/integration_tests
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ Setup instruction auto-generated by `langgraph template lock`. DO NOT EDIT MANUA

### Setup Model

The defaults values for `model_name` are shown below:
The defaults values for `model` are shown below:

```yaml
model_name: anthropic/claude-3-5-sonnet-20240620
model: anthropic/claude-3-5-sonnet-20240620
```
Follow the instructions below to get set up, or pick one of the additional options.
Expand All @@ -58,18 +58,20 @@ To use Anthropic's chat models:
```
ANTHROPIC_API_KEY=your-api-key
```
#### OpenAI
To use OpenAI's chat models:
1. Sign up for an [OpenAI API key](https://platform.openai.com/signup).
2. Once you have your API key, add it to your `.env` file:
```
OPENAI_API_KEY=your-api-key
```
<!--
End setup instructions
-->
Expand Down Expand Up @@ -169,7 +171,7 @@ Configuration auto-generated by `langgraph template lock`. DO NOT EDIT MANUALLY.
"agent": {
"type": "object",
"properties": {
"model_name": {
"model": {
"type": "string",
"default": "anthropic/claude-3-5-sonnet-20240620",
"description": "The name of the language model to use for the agent. Should be in the form: provider/model-name.",
Expand Down Expand Up @@ -295,4 +297,4 @@ Configuration auto-generated by `langgraph template lock`. DO NOT EDIT MANUALLY.
}
}
}
-->
-->
34 changes: 17 additions & 17 deletions ntbk/testing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"outputs": [],
"source": [
"from langgraph_sdk import get_client\n",
"\n",
"client = get_client(url=\"http://localhost:56396\")"
]
},
Expand All @@ -55,41 +56,38 @@
"metadata": {},
"outputs": [],
"source": [
"schema = {\n",
"schema = {\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"companies\": {\n",
" \"type\": \"array\",\n",
" \"items\": {\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"name\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"Company name\"\n",
" },\n",
" \"name\": {\"type\": \"string\", \"description\": \"Company name\"},\n",
" \"technologies\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"Brief summary of key technologies used by the company\"\n",
" \"description\": \"Brief summary of key technologies used by the company\",\n",
" },\n",
" \"market_share\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"Overview of market share for this company\"\n",
" \"description\": \"Overview of market share for this company\",\n",
" },\n",
" \"future_outlook\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"Brief summary of future prospects and developments in the field for this company\"\n",
" \"description\": \"Brief summary of future prospects and developments in the field for this company\",\n",
" },\n",
" \"key_powers\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"Which of the 7 Powers (Scale Economies, Network Economies, Counter Positioning, Switching Costs, Branding, Cornered Resource, Process Power) best describe this company's competitive advantage\"\n",
" }\n",
" \"description\": \"Which of the 7 Powers (Scale Economies, Network Economies, Counter Positioning, Switching Costs, Branding, Cornered Resource, Process Power) best describe this company's competitive advantage\",\n",
" },\n",
" },\n",
" \"required\": [\"name\", \"technologies\", \"market_share\", \"future_outlook\"]\n",
" \"required\": [\"name\", \"technologies\", \"market_share\", \"future_outlook\"],\n",
" },\n",
" \"description\": \"List of companies\"\n",
" \"description\": \"List of companies\",\n",
" }\n",
" },\n",
" \"required\": [\"companies\"]\n",
" \"required\": [\"companies\"],\n",
"}"
]
},
Expand Down Expand Up @@ -118,7 +116,7 @@
"# Stream\n",
"async for event in client.runs.stream(\n",
" thread[\"thread_id\"],\n",
" assistant_id= \"agent\",\n",
" assistant_id=\"agent\",\n",
" input={\n",
" \"topic\": topic,\n",
" \"extraction_schema\": schema,\n",
Expand Down Expand Up @@ -223,10 +221,11 @@
"source": [
"from IPython.display import Markdown, display\n",
"\n",
"\n",
"def format_llm_chip_info(data):\n",
" markdown_text = \"# Top 5 Chip Providers for LLM Training\\n\\n\"\n",
" \n",
" for company in data['companies']:\n",
"\n",
" for company in data[\"companies\"]:\n",
" markdown_text += f\"\"\"\n",
"## {company['name']}\n",
"\n",
Expand All @@ -240,9 +239,10 @@
"\n",
"---\n",
"\"\"\"\n",
" \n",
"\n",
" return Markdown(markdown_text)\n",
"\n",
"\n",
"# Display the formatted markdown\n",
"display(format_llm_chip_info(current_state[\"values\"][\"info\"]))"
]
Expand Down
2 changes: 1 addition & 1 deletion src/enrichment_agent/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class Configuration:
"""The configuration for the agent."""

model_name: Annotated[str, {"__template_metadata__": {"kind": "llm"}}] = field(
model: Annotated[str, {"__template_metadata__": {"kind": "llm"}}] = field(
default="anthropic/claude-3-5-sonnet-20240620",
metadata={
"description": "The name of the language model to use for the agent. "
Expand Down
14 changes: 6 additions & 8 deletions src/enrichment_agent/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from enrichment_agent.utils import init_model


# Define the nodes
async def call_agent_model(
state: State, *, config: Optional[RunnableConfig] = None
) -> Dict[str, Any]:
Expand Down Expand Up @@ -115,6 +114,12 @@ async def reflect(
p = prompts.MAIN_PROMPT.format(
info=json.dumps(state.extraction_schema, indent=2), topic=state.topic
)
last_message = state.messages[-1]
if not isinstance(last_message, AIMessage):
raise ValueError(
f"{reflect.__name__} expects the last message in the state to be an AI message with tool calls."
f" Got: {type(last_message)}"
)
messages = [HumanMessage(content=p)] + state.messages[:-1]
presumed_info = state.info
checker_prompt = """I am thinking of calling the info tool with the info below. \
Expand All @@ -128,13 +133,6 @@ async def reflect(
raw_model = init_model(config)
bound_model = raw_model.with_structured_output(InfoIsSatisfactory)
response = cast(InfoIsSatisfactory, await bound_model.ainvoke(messages))
last_message = state.messages[-1]
if not isinstance(last_message, AIMessage):
raise ValueError(
f"{reflect.__name__} expects the last message in the state to be an AI message with tool calls."
f" Got: {type(last_message)}"
)

if response.is_satisfactory and presumed_info:
return {
"info": presumed_info,
Expand Down
2 changes: 1 addition & 1 deletion src/enrichment_agent/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_message_text(msg: AnyMessage) -> str:
def init_model(config: Optional[RunnableConfig] = None) -> BaseChatModel:
"""Initialize the configured chat model."""
configuration = Configuration.from_runnable_config(config)
fully_specified_name = configuration.model_name
fully_specified_name = configuration.model
if "/" in fully_specified_name:
provider, model = fully_specified_name.split("/", maxsplit=1)
else:
Expand Down
3 changes: 1 addition & 2 deletions tests/integration_tests/test_graph.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Any, Dict

import pytest
from langsmith import unit

from enrichment_agent import graph
from langsmith import unit


@pytest.fixture(scope="function")
Expand Down

0 comments on commit 75af61f

Please sign in to comment.