Skip to content

Commit

Permalink
episode 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Cutwell committed Nov 9, 2023
1 parent 339838d commit d860ce0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
8 changes: 7 additions & 1 deletion .envrc.example.sh
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export OPENAI_API_KEY=
export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_ENDPOINT=https://api.smith.langchain.com
export LANGCHAIN_API_KEY=<your-api-key>
# if LANGCHAIN_PROJECT not specified, defaults to "default"
export LANGCHAIN_PROJECT=<your-project>

export OPENAI_API_KEY=<your-openai-api-key>
13 changes: 3 additions & 10 deletions my-app/my_app/chain.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
from langchain.chat_models import ChatOpenAI
from langchain.prompts import ChatPromptTemplate
from langchain import hub

_prompt = ChatPromptTemplate.from_messages(
[
(
"system",
"You are a helpful assistant who speaks like a pirate",
),
("human", "{text}"),
]
)

_prompt = hub.pull("cutwell/best-pirate-ever")
_model = ChatOpenAI()

# if you update this, you MUST also update ../pyproject.toml
Expand Down
33 changes: 32 additions & 1 deletion my-app/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions my-app/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ readme = "README.md"
python = ">=3.8.1,<4.0"
langchain = ">=0.0.313, <0.1"
openai = "^0.28.1"
langchainhub = "^0.1.13"

[tool.poetry.group.dev.dependencies]
langchain-cli = ">=0.0.4"
Expand Down
12 changes: 10 additions & 2 deletions my-app/tests/test_chain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
from my_app.chain import chain
import langsmith
from datetime import datetime

def test_chain():
print(
chain.invoke({"text": "Hi there, do you have any gold for me?"}).content
client = langsmith.Client()

chain_results = client.run_on_dataset(
dataset_name="pirate-dataset",
llm_or_chain_factory=chain,
project_name=f"pirate-dataset-test-{int(datetime.now().strftime('%Y%m%d%H%M%S'))}",
concurrency_level=5,
verbose=True,
)

0 comments on commit d860ce0

Please sign in to comment.