Skip to content

Commit

Permalink
style: format code with Autopep8
Browse files Browse the repository at this point in the history
This commit fixes the style issues introduced in a5e83a8 according to the output
from Autopep8.

Details: None
  • Loading branch information
deepsource-autofix[bot] authored Dec 20, 2024
1 parent a5e83a8 commit ac49d27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
9 changes: 6 additions & 3 deletions python/openwebui/pipe_mcts.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def get_chunk_content(self, chunk):
if "content" in delta:
yield delta["content"]
except json.JSONDecodeError:
logger.error(f'ChunkDecodeError: unable to parse "{chunk_str[:100]}"')
logger.error(
f'ChunkDecodeError: unable to parse "{chunk_str[:100]}"')


# =============================================================================
Expand Down Expand Up @@ -436,7 +437,8 @@ async def update_approach(self, answer: str, improvements: str):
return await self.generate_completion(prompt)

async def evaluate_answer(self, answer: str):
prompt = eval_answer_prompt.format(question=self.question, answer=answer)
prompt = eval_answer_prompt.format(
question=self.question, answer=answer)
result = await self.generate_completion(prompt)
try:
score = int(re.search(r"\d+", result).group())
Expand Down Expand Up @@ -672,7 +674,8 @@ async def pipe(
if match:
backend, model_name = match.groups()
else:
logger.error("Model ID should be in the format '*.mcts/backend/model_name'")
logger.error(
"Model ID should be in the format '*.mcts/backend/model_name'")
logger.error(f"Invalid model ID: {model_id}")
return ""

Expand Down
17 changes: 11 additions & 6 deletions python/openwebui/pipe_react.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@


class SendCitationType(Protocol):
def __call__(self, url: str, title: str, content: str) -> Awaitable[None]: ...
def __call__(self, url: str, title: str,
content: str) -> Awaitable[None]: ...


class SendStatusType(Protocol):
Expand Down Expand Up @@ -81,7 +82,8 @@ class Valves(BaseModel):
LANGFUSE_URL: str = Field(
default="http://langfuse-server:3000", description="Langfuse URL"
)
MODEL_PREFIX: str = Field(default="ReAct", description="Prefix before model ID")
MODEL_PREFIX: str = Field(
default="ReAct", description="Prefix before model ID")

def __init__(self):
self.type = "manifold"
Expand All @@ -104,7 +106,8 @@ def pipes(self) -> list[dict[str, str]]:
def setup(self):
v = self.valves
if not v.OPENAI_API_KEY or not v.OPENAI_BASE_URL:
raise Exception("Error: OPENAI_API_KEY or OPENAI_BASE_URL is not set")
raise Exception(
"Error: OPENAI_API_KEY or OPENAI_BASE_URL is not set")
self.openai_kwargs = {
"base_url": v.OPENAI_BASE_URL,
"api_key": v.OPENAI_API_KEY,
Expand Down Expand Up @@ -134,8 +137,9 @@ async def pipe(

self.setup()

model_id = body["model"][body["model"].rfind(".") + 1 :]
model = ChatOpenAI(model=model_id, **self.openai_kwargs) # type: ignore
model_id = body["model"][body["model"].rfind(".") + 1:]
model = ChatOpenAI(model=model_id, **
self.openai_kwargs) # type: ignore
if self.langfuse_kwargs:
user_kwargs = {"user_id": __user__["id"]} if __user__ else {}
callback_kwargs = self.langfuse_kwargs | user_kwargs
Expand Down Expand Up @@ -174,7 +178,8 @@ async def pipe(
graph = create_react_agent(model, tools=tools)
inputs = {"messages": body["messages"]}
num_tool_calls = 0
async for event in graph.astream_events(inputs, version="v2", config=config): # type: ignore
# type: ignore
async for event in graph.astream_events(inputs, version="v2", config=config):
kind = event["event"]
data = event["data"]
if kind == "on_chat_model_stream":
Expand Down

0 comments on commit ac49d27

Please sign in to comment.