Skip to content

Commit

Permalink
fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
D-W- committed Apr 30, 2024
1 parent 005c5fa commit 1f568c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
24 changes: 11 additions & 13 deletions examples/flex-flows/langchain-eval/flow.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from dataclasses import dataclass
from pathlib import Path

from promptflow.tracing import trace
from promptflow.connections import CustomConnection


from langchain.evaluation import load_evaluator
from langchain.chat_models import AzureChatOpenAI, ChatAnthropic
from langchain.evaluation import load_evaluator

from promptflow.connections import CustomConnection
from promptflow.tracing import trace


@dataclass
Expand All @@ -23,7 +20,9 @@ def __init__(self, custom_connection: CustomConnection):

# create llm according to the secrets in custom connection
if "anthropic_api_key" in self.custom_connection.secrets:
self.llm = ChatAnthropic(temperature=0, anthropic_api_key=self.custom_connection.secrets["anthropic_api_key"])
self.llm = ChatAnthropic(
temperature=0, anthropic_api_key=self.custom_connection.secrets["anthropic_api_key"]
)
elif "openai_api_key" in self.custom_connection.secrets:
self.llm = AzureChatOpenAI(
deployment_name="gpt-35-turbo",
Expand All @@ -35,17 +34,16 @@ def __init__(self, custom_connection: CustomConnection):
)
else:
raise ValueError("No valid API key found in the connection.")

self.evaluator = load_evaluator("criteria", llm=self.llm, criteria="conciseness")

@trace
def __call__(
self, input: str, prediction: str,
self,
input: str,
prediction: str,
) -> Result:
"""Evaluate with langchain evaluator."""

eval_result = self.evaluator.evaluate_strings(
prediction=prediction, input=input
)
eval_result = self.evaluator.evaluate_strings(prediction=prediction, input=input)
return Result(**eval_result)

6 changes: 3 additions & 3 deletions examples/flex-flows/langchain-eval/langchain-eval.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create a custom connection to protect your LLM's API key\n",
"## Create a custom connection to protect your API key\n",
"\n",
"You can protect your LLM's API key in custom connection's secrets."
"You can protect your API key in custom connection's secrets."
]
},
{
Expand All @@ -71,7 +71,7 @@
" # load environment variables from .env file\n",
" load_dotenv()\n",
"\n",
"# put LLM's API key in secrets\n",
"# put API key in secrets\n",
"connection = CustomConnection(\n",
" name=\"my_llm_connection\",\n",
" secrets={\n",
Expand Down

0 comments on commit 1f568c2

Please sign in to comment.