From 7d125a93a59be9d55576358f002622e29bf40473 Mon Sep 17 00:00:00 2001 From: Shroominic Date: Tue, 19 Nov 2024 17:36:25 +0800 Subject: [PATCH] ruff fix --- .pre-commit-config.yaml | 24 +++++++++---------- examples/async/expert_answer.py | 3 ++- examples/async/startup_names.py | 3 ++- examples/custom_model_display.py | 3 ++- examples/decorator.py | 3 ++- examples/dict_type.py | 3 ++- examples/dynamic_router.py | 3 ++- examples/enums.py | 3 ++- examples/error_output.py | 3 ++- .../experiments/parallel_console_streaming.py | 7 +++--- examples/jinja.py | 3 ++- examples/literals.py | 3 ++- examples/models/azure.py | 3 ++- examples/models/claude3.py | 3 ++- examples/models/groq_models.py | 3 ++- examples/models/llamacpp.py | 3 ++- examples/models/ollama.py | 3 ++- examples/openai_json_mode.py | 3 ++- examples/pydantic_validation.py | 3 ++- examples/rag_with_deps.py | 5 ++-- examples/simple/gather_infos.py | 3 ++- examples/simple/task_comparison.py | 3 ++- examples/simple/tutorial.py | 3 ++- examples/static_router.py | 3 ++- examples/stream_runnables.py | 5 ++-- examples/union_types.py | 3 ++- examples/vision.py | 3 ++- src/funcchain/syntax/decorators.py | 6 ++--- tests/async_test.py | 3 ++- tests/models/llamacpp_test.py | 3 ++- tests/models/ollama_test.py | 3 ++- tests/models/openai_test.py | 3 ++- 32 files changed, 78 insertions(+), 50 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3cd30bf..52fc0c3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,14 +1,14 @@ repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 - hooks: - - id: end-of-file-fixer - - id: trailing-whitespace + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.7 - hooks: - - id: ruff - args: [--fix] - - id: ruff-format - types_or: [python, pyi, jupyter] + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.7.4 + hooks: + - id: ruff + args: [--fix] + - id: ruff-format + types_or: [python, pyi, jupyter] diff --git a/examples/async/expert_answer.py b/examples/async/expert_answer.py index faa7852..9bd568c 100644 --- a/examples/async/expert_answer.py +++ b/examples/async/expert_answer.py @@ -2,9 +2,10 @@ from asyncio import run as _await from random import shuffle -from funcchain import achain, settings from pydantic import BaseModel +from funcchain import achain, settings + settings.temperature = 1 diff --git a/examples/async/startup_names.py b/examples/async/startup_names.py index 6f5f2c3..7695c8b 100644 --- a/examples/async/startup_names.py +++ b/examples/async/startup_names.py @@ -1,8 +1,9 @@ import asyncio -from funcchain import achain, settings from pydantic import BaseModel +from funcchain import achain, settings + settings.temperature = 1 diff --git a/examples/custom_model_display.py b/examples/custom_model_display.py index 1bfe69a..a8a575f 100644 --- a/examples/custom_model_display.py +++ b/examples/custom_model_display.py @@ -1,6 +1,7 @@ -from funcchain import chain from pydantic import BaseModel +from funcchain import chain + class Task(BaseModel): name: str diff --git a/examples/decorator.py b/examples/decorator.py index b833333..6232d20 100644 --- a/examples/decorator.py +++ b/examples/decorator.py @@ -1,10 +1,11 @@ from operator import itemgetter -from funcchain.syntax import chain, runnable from langchain_community.embeddings import OpenAIEmbeddings from langchain_community.vectorstores.faiss import FAISS from langchain_core.runnables import Runnable, RunnablePassthrough +from funcchain.syntax import chain, runnable + @runnable def generate_poem(topic: str, context: str) -> str: diff --git a/examples/dict_type.py b/examples/dict_type.py index 31552f5..67a9cc3 100644 --- a/examples/dict_type.py +++ b/examples/dict_type.py @@ -1,6 +1,7 @@ -from funcchain import chain, settings from pydantic import BaseModel +from funcchain import chain, settings + settings.console_stream = True settings.llm = "llamacpp/openchat-3.5-0106:Q3_K_M" diff --git a/examples/dynamic_router.py b/examples/dynamic_router.py index cbff138..83f8931 100644 --- a/examples/dynamic_router.py +++ b/examples/dynamic_router.py @@ -1,9 +1,10 @@ from enum import Enum from typing import Any, Callable, TypedDict -from funcchain.syntax.executable import compile_runnable from pydantic import BaseModel, Field +from funcchain.syntax.executable import compile_runnable + # Dynamic Router Definition: diff --git a/examples/enums.py b/examples/enums.py index 46dcb48..b7d183f 100644 --- a/examples/enums.py +++ b/examples/enums.py @@ -1,8 +1,9 @@ from enum import Enum -from funcchain import chain from pydantic import BaseModel +from funcchain import chain + class Answer(str, Enum): yes = "yes" diff --git a/examples/error_output.py b/examples/error_output.py index 92d77e7..0f5f2a9 100644 --- a/examples/error_output.py +++ b/examples/error_output.py @@ -1,6 +1,7 @@ -from funcchain import BaseModel, Error, chain from rich import print +from funcchain import BaseModel, Error, chain + class User(BaseModel): name: str diff --git a/examples/experiments/parallel_console_streaming.py b/examples/experiments/parallel_console_streaming.py index 693ee65..22dd5ba 100644 --- a/examples/experiments/parallel_console_streaming.py +++ b/examples/experiments/parallel_console_streaming.py @@ -3,14 +3,15 @@ from typing import AsyncGenerator from uuid import uuid4 -from funcchain import achain, settings -from funcchain.backend.streaming import astream_to -from funcchain.utils.token_counter import count_tokens from rich.console import Console from rich.layout import Layout from rich.live import Live from rich.panel import Panel +from funcchain import achain, settings +from funcchain.backend.streaming import astream_to +from funcchain.utils.token_counter import count_tokens + class RenderChain: def __init__(self, renderer: "Renderer", name: str) -> None: diff --git a/examples/jinja.py b/examples/jinja.py index a82fbc7..9378a61 100644 --- a/examples/jinja.py +++ b/examples/jinja.py @@ -1,6 +1,7 @@ -from funcchain import chain, settings from pydantic import BaseModel +from funcchain import chain, settings + settings.console_stream = True diff --git a/examples/literals.py b/examples/literals.py index 5948e5e..58bd78f 100644 --- a/examples/literals.py +++ b/examples/literals.py @@ -1,8 +1,9 @@ from typing import Literal -from funcchain import chain from pydantic import BaseModel +from funcchain import chain + # just a silly example to schowcase the Literal type class Ranking(BaseModel): diff --git a/examples/models/azure.py b/examples/models/azure.py index 60da581..7dcce92 100644 --- a/examples/models/azure.py +++ b/examples/models/azure.py @@ -1,6 +1,7 @@ -from funcchain import chain, settings from pydantic import BaseModel, Field +from funcchain import chain, settings + # define your model class SentimentAnalysis(BaseModel): diff --git a/examples/models/claude3.py b/examples/models/claude3.py index f37f6db..734de45 100644 --- a/examples/models/claude3.py +++ b/examples/models/claude3.py @@ -1,8 +1,9 @@ from typing import Annotated -from funcchain import Depends, chain, settings from langchain.document_loaders.pdf import PyPDFLoader +from funcchain import Depends, chain, settings + settings.llm = "anthropic/claude-3-opus-20240229" diff --git a/examples/models/groq_models.py b/examples/models/groq_models.py index 515a068..5eb66c0 100644 --- a/examples/models/groq_models.py +++ b/examples/models/groq_models.py @@ -1,8 +1,9 @@ -from funcchain import chain, settings from langchain_groq import ChatGroq from pydantic import BaseModel, Field from rich import print +from funcchain import chain, settings + class SentimentAnalysis(BaseModel): analysis: str = Field(description="A description of the analysis") diff --git a/examples/models/llamacpp.py b/examples/models/llamacpp.py index 18c1cf0..61d5388 100644 --- a/examples/models/llamacpp.py +++ b/examples/models/llamacpp.py @@ -1,7 +1,8 @@ -from funcchain import chain, settings from pydantic import BaseModel, Field from rich import print +from funcchain import chain, settings + # define your model class SentimentAnalysis(BaseModel): diff --git a/examples/models/ollama.py b/examples/models/ollama.py index 76328c8..cd54736 100644 --- a/examples/models/ollama.py +++ b/examples/models/ollama.py @@ -1,7 +1,8 @@ -from funcchain import chain, settings from pydantic import BaseModel, Field from rich import print +from funcchain import chain, settings + # define your model class SentimentAnalysis(BaseModel): diff --git a/examples/openai_json_mode.py b/examples/openai_json_mode.py index 135887e..02ca780 100644 --- a/examples/openai_json_mode.py +++ b/examples/openai_json_mode.py @@ -1,6 +1,7 @@ -from funcchain import chain, settings from pydantic import BaseModel +from funcchain import chain, settings + settings.console_stream = True diff --git a/examples/pydantic_validation.py b/examples/pydantic_validation.py index 83b5d83..e4211a3 100644 --- a/examples/pydantic_validation.py +++ b/examples/pydantic_validation.py @@ -1,6 +1,7 @@ -from funcchain import chain, settings from pydantic import BaseModel, field_validator +from funcchain import chain, settings + # settings.llm = "ollama/openchat" settings.console_stream = True diff --git a/examples/rag_with_deps.py b/examples/rag_with_deps.py index 8465108..7f7880d 100644 --- a/examples/rag_with_deps.py +++ b/examples/rag_with_deps.py @@ -1,11 +1,12 @@ from operator import itemgetter from typing import Annotated -from funcchain.syntax import chain, runnable -from funcchain.syntax.params import Depends from langchain_community.embeddings import OpenAIEmbeddings from langchain_community.vectorstores.faiss import FAISS +from funcchain.syntax import chain, runnable +from funcchain.syntax.params import Depends + retriever = FAISS.from_texts( [ "cold showers are good for your immune system", diff --git a/examples/simple/gather_infos.py b/examples/simple/gather_infos.py index d8234f1..1598ca1 100644 --- a/examples/simple/gather_infos.py +++ b/examples/simple/gather_infos.py @@ -1,6 +1,7 @@ -from funcchain import chain, settings from pydantic import BaseModel +from funcchain import chain, settings + # settings.llm = "ollama/openchat" settings.console_stream = True diff --git a/examples/simple/task_comparison.py b/examples/simple/task_comparison.py index b3611dd..972e463 100644 --- a/examples/simple/task_comparison.py +++ b/examples/simple/task_comparison.py @@ -1,8 +1,9 @@ import asyncio -from funcchain import achain, chain from pydantic import BaseModel +from funcchain import achain, chain + class Task(BaseModel): name: str diff --git a/examples/simple/tutorial.py b/examples/simple/tutorial.py index 6eb35f7..11596ef 100644 --- a/examples/simple/tutorial.py +++ b/examples/simple/tutorial.py @@ -1,7 +1,8 @@ # %% -from funcchain import chain from pydantic import BaseModel, Field, validator +from funcchain import chain + # %% def say_hello(num: int) -> str: diff --git a/examples/static_router.py b/examples/static_router.py index 5af3576..fe0f4a9 100644 --- a/examples/static_router.py +++ b/examples/static_router.py @@ -1,9 +1,10 @@ from enum import Enum from typing import Any -from funcchain import chain, settings from pydantic import BaseModel, Field +from funcchain import chain, settings + settings.console_stream = True # settings.llm = "ollama/openhermes2.5-mistral" diff --git a/examples/stream_runnables.py b/examples/stream_runnables.py index 53bd2d1..f2fc902 100644 --- a/examples/stream_runnables.py +++ b/examples/stream_runnables.py @@ -1,12 +1,13 @@ from typing import AsyncIterator, Iterator +from langchain_core.messages import AIMessage, HumanMessage +from langchain_core.runnables import RunnableGenerator, RunnableSerializable + from funcchain import chain from funcchain.syntax import runnable from funcchain.syntax.components import RouterChat from funcchain.syntax.components.handler import create_chat_handler from funcchain.utils.msg_tools import msg_to_str -from langchain_core.messages import AIMessage, HumanMessage -from langchain_core.runnables import RunnableGenerator, RunnableSerializable # settings.llm = "ollama/openchat" diff --git a/examples/union_types.py b/examples/union_types.py index 8dc6afc..5c16b5b 100644 --- a/examples/union_types.py +++ b/examples/union_types.py @@ -1,6 +1,7 @@ -from funcchain import chain from pydantic import BaseModel, Field +from funcchain import chain + class Item(BaseModel): name: str = Field(description="Name of the item") diff --git a/examples/vision.py b/examples/vision.py index cf2881d..bc19635 100644 --- a/examples/vision.py +++ b/examples/vision.py @@ -1,6 +1,7 @@ -from funcchain import Image, chain, settings from pydantic import BaseModel, Field +from funcchain import Image, chain, settings + settings.llm = "openai/gpt-4-vision-preview" # settings.llm = "ollama/bakllava" settings.console_stream = True diff --git a/src/funcchain/syntax/decorators.py b/src/funcchain/syntax/decorators.py index 41a5774..06fd30c 100644 --- a/src/funcchain/syntax/decorators.py +++ b/src/funcchain/syntax/decorators.py @@ -15,8 +15,7 @@ @overload def runnable( f: Callable[..., OutputT], -) -> Runnable[dict[str, Any], OutputT]: - ... +) -> Runnable[dict[str, Any], OutputT]: ... @overload @@ -24,8 +23,7 @@ def runnable( *, llm: UniversalChatModel = None, settings: SettingsOverride = {}, -) -> Callable[[Callable[..., OutputT]], Runnable[dict[str, Any], OutputT]]: - ... +) -> Callable[[Callable[..., OutputT]], Runnable[dict[str, Any], OutputT]]: ... def runnable( diff --git a/tests/async_test.py b/tests/async_test.py index d5e3830..defa238 100644 --- a/tests/async_test.py +++ b/tests/async_test.py @@ -2,9 +2,10 @@ from asyncio import run as _await from random import shuffle -from funcchain import achain, settings from pydantic import BaseModel +from funcchain import achain, settings + settings.temperature = 1 settings.llm = "openai/gpt-3.5-turbo-1106" diff --git a/tests/models/llamacpp_test.py b/tests/models/llamacpp_test.py index cb5f38c..960db82 100644 --- a/tests/models/llamacpp_test.py +++ b/tests/models/llamacpp_test.py @@ -1,7 +1,8 @@ import pytest -from funcchain import Image, chain, settings from pydantic import BaseModel, Field +from funcchain import Image, chain, settings + class Task(BaseModel): description: str diff --git a/tests/models/ollama_test.py b/tests/models/ollama_test.py index 1cf0546..173a6a6 100644 --- a/tests/models/ollama_test.py +++ b/tests/models/ollama_test.py @@ -1,7 +1,8 @@ import pytest -from funcchain import Image, chain, settings from pydantic import BaseModel, Field +from funcchain import Image, chain, settings + class Task(BaseModel): description: str diff --git a/tests/models/openai_test.py b/tests/models/openai_test.py index efbabed..6425b5d 100644 --- a/tests/models/openai_test.py +++ b/tests/models/openai_test.py @@ -1,6 +1,7 @@ -from funcchain import chain, settings from pydantic import BaseModel, Field +from funcchain import chain, settings + class Task(BaseModel): name: str