Getting this error with Perplexity models: litellm.exceptions.BadRequestError: litellm.BadRequestError: PerplexityException - Error code: 400 - {'error': {'message': 'custom stop words are not implemented for completions.', 'type': 'unsupported_parameter', 'code': 400}}
.
Code to replicate:
import os
from dotenv import load_dotenv
from crewai import Agent, Task, Crew, LLM
from pydantic import BaseModel
from typing import Optional
load_dotenv()
class GreetingOutput(BaseModel):
message: str
recipient: Optional[str] = "World"
sentiment: Optional[str] = "positive"
def __str__(self):
return f"{self.message} {self.recipient}! (Sentiment: {self.sentiment})"
llm = LLM(
api_key=os.environ.get('PERPLEXITY_API_KEY'),
temperature=0.01,
model="perplexity/sonar",
)
hello_agent = Agent(
role='Greeter',
goal='Deliver friendly greetings',
backstory='A cheerful agent whose purpose is to greet people warmly',
llm=llm,
)
greeting_task = Task(
description="""Generate a friendly hello world message.
Your response should be formatted as a JSON object with the following fields:
- message: The greeting message
- recipient: Who the message is for (default: "World")
- sentiment: The emotional tone of the message (default: "positive")
""",
expected_output="Instance of GreetingOutput model",
agent=hello_agent,
output_pydantic=GreetingOutput,
)
crew = Crew(
agents=[hello_agent],
tasks=[greeting_task]
)
result = crew.kickoff()
print(result.pydantic.sentiment)
There was similar error with o1 mini
model mentioned, so I don’t think it is Perplexity specific. Looks like CrewAI pushes some stop word, even if you ask it not to.