Skip to content

Commit

Permalink
clean test
Browse files Browse the repository at this point in the history
  • Loading branch information
tcapelle committed Oct 10, 2024
1 parent ad5f021 commit 125d583
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions weave/flow/scorer/llm_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ class PromptScorer(LLMScorer):

@field_validator('user_prompt')
def validate_user_prompt(cls, v):
"The user prompt must contain the `model_output` variable."
if "{model_output}" not in v:
raise ValueError("The user prompt must contain the `model_output` variable.")
raise ValueError("The user prompt must contain the `{model_output}` variable.")
return v

def score(self, model_output: Any) -> Any:
Expand Down Expand Up @@ -86,35 +85,35 @@ def score(self, model_output: Any) -> Any:


if __name__ == "__main__":
# try:
# import openai
# client = openai.OpenAI()
# scorer = EmbeddingScorer(
# client=client,
# model="text-embedding-3-small")
# print(scorer.score("I don't know", "I don't know"))
# except Exception as e:
# print("Install openai to run this script")
try:
import openai
client = openai.OpenAI()
scorer = EmbeddingScorer(
client=client,
model="text-embedding-3-small")
print(scorer.score("I don't know", "I don't know"))
except Exception as e:
print("Install openai to run this script")

# try:
# import openai
# client = openai.OpenAI()
# scorer = OpenAIModerationScorer(
# client=client,
# model="omni-moderation-latest")
# print(scorer.score("I should kill myself"))
# except Exception as e:
# print("Install openai to run this script")
try:
import openai
client = openai.OpenAI()
scorer = OpenAIModerationScorer(
client=client,
model="omni-moderation-latest")
print(scorer.score("I should kill myself"))
except Exception as e:
print("Install openai to run this script")

# try:
try:
import openai
client = openai.OpenAI()
scorer = PromptScorer(
client=client,
model="gpt-4o",
system_prompt="You are a helpful assistant.",
user_prompt="Extract the entity from this phrase: \m {model_output}")
user_prompt="Extract the entity from this phrase: \n {model_output}")
print(scorer.score("The cat is happy"))
# except Exception as e:
# print("Install openai to run this script")
except Exception as e:
print("Install openai to run this script")

0 comments on commit 125d583

Please sign in to comment.