Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Import Sorting #638

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ target-version = "py39"

[lint]
select = [
# isort
"I",
# bugbear rules
"B",
# remove unused imports
Expand Down
3 changes: 2 additions & 1 deletion examples/anthropic/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pydantic import BaseModel
import anthropic
from pydantic import BaseModel

import instructor

# Patching the Anthropics client with the instructor for enhanced capabilities
Expand Down
9 changes: 5 additions & 4 deletions examples/auto-ticketer/run.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import instructor
from openai import OpenAI

from enum import Enum
from typing import Optional

from openai import OpenAI
from pydantic import BaseModel, Field
from enum import Enum

import instructor

client = instructor.from_openai(OpenAI())

Expand Down
5 changes: 3 additions & 2 deletions examples/avail/run.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from pydantic import BaseModel, Field
from typing import Literal
from collections.abc import Iterable
from datetime import datetime, timedelta
from typing import Literal

from openai import OpenAI
from pydantic import BaseModel, Field

import instructor

client = instructor.from_openai(OpenAI())
Expand Down
5 changes: 3 additions & 2 deletions examples/avail/run_mixtral.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
from pydantic import BaseModel, Field
from typing import Literal
from datetime import datetime, timedelta
from typing import Literal

from openai import OpenAI
from pydantic import BaseModel, Field

import instructor

client = instructor.from_openai(
Expand Down
5 changes: 3 additions & 2 deletions examples/batch-classification/run-cache.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import instructor
import asyncio
from enum import Enum

from openai import AsyncOpenAI
from pydantic import BaseModel, Field, field_validator
from enum import Enum

import instructor

client = instructor.from_openai(AsyncOpenAI(), mode=instructor.Mode.TOOLS)
sem = asyncio.Semaphore(5)
Expand Down
7 changes: 4 additions & 3 deletions examples/batch-classification/run.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import json
import instructor
import asyncio
import json
from enum import Enum

from openai import AsyncOpenAI
from pydantic import BaseModel, Field, field_validator
from enum import Enum

import instructor

client = AsyncOpenAI()
client = instructor.from_openai(client, mode=instructor.Mode.TOOLS)
Expand Down
6 changes: 3 additions & 3 deletions examples/batch-classification/run_langsmith.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import instructor
import asyncio
from enum import Enum

from langsmith import traceable
from langsmith.wrappers import wrap_openai

from openai import AsyncOpenAI
from pydantic import BaseModel, Field, field_validator
from enum import Enum

import instructor

client = wrap_openai(AsyncOpenAI())
client = instructor.from_openai(client, mode=instructor.Mode.TOOLS)
Expand Down
7 changes: 4 additions & 3 deletions examples/caching/example_diskcache.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import functools
import inspect
import instructor
import diskcache

from openai import OpenAI, AsyncOpenAI
import diskcache
from openai import AsyncOpenAI, OpenAI
from pydantic import BaseModel

import instructor

client = instructor.from_openai(OpenAI())
aclient = instructor.from_openai(AsyncOpenAI())

Expand Down
7 changes: 4 additions & 3 deletions examples/caching/example_redis.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import redis
import functools
import inspect
import instructor

from pydantic import BaseModel
import redis
from openai import OpenAI
from pydantic import BaseModel

import instructor

client = instructor.from_openai(OpenAI())
cache = redis.Redis("localhost")
Expand Down
6 changes: 4 additions & 2 deletions examples/caching/lru.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import instructor
import functools

from openai import OpenAI
from pydantic import BaseModel
import functools

import instructor

client = instructor.from_openai(OpenAI())

Expand Down
7 changes: 4 additions & 3 deletions examples/chain-of-density/chain_of_density.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from pydantic import BaseModel, Field, field_validator
import instructor
import nltk
from openai import OpenAI
import spacy
from openai import OpenAI
from pydantic import BaseModel, Field, field_validator

import instructor

client = instructor.from_openai(OpenAI())
nlp = spacy.load("en_core_web_sm")
Expand Down
8 changes: 5 additions & 3 deletions examples/chain-of-density/finetune.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from openai import OpenAI
from chain_of_density import summarize_article
import csv
import logging
import instructor

from chain_of_density import summarize_article
from openai import OpenAI
from pydantic import BaseModel, Field

import instructor

logging.basicConfig(level=logging.INFO)

client = instructor.from_openai(OpenAI())
Expand Down
6 changes: 3 additions & 3 deletions examples/citation_with_extraction/citation_fuzzy_match.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import instructor

from loguru import logger
from openai import OpenAI
from pydantic import Field, BaseModel, FieldValidationInfo, model_validator
from pydantic import BaseModel, Field, FieldValidationInfo, model_validator

import instructor

client = instructor.from_openai(OpenAI())

Expand Down
1 change: 0 additions & 1 deletion examples/citation_with_extraction/diagram.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import erdantic as erd

from citation_fuzzy_match import QuestionAnswer

diagram = erd.create(QuestionAnswer)
Expand Down
12 changes: 6 additions & 6 deletions examples/citation_with_extraction/main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import json
import logging
import os
from collections.abc import Iterable
from fastapi import FastAPI, Request, HTTPException

from fastapi import FastAPI, HTTPException, Request
from fastapi.params import Depends
from instructor import OpenAISchema
from openai import OpenAI
from pydantic import BaseModel, Field
from starlette.responses import StreamingResponse

import os
import instructor
import logging

from openai import OpenAI
from instructor import OpenAISchema
from instructor.dsl.multitask import MultiTaskBase

client = instructor.from_openai(OpenAI())
Expand Down
2 changes: 1 addition & 1 deletion examples/citation_with_extraction/modal_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from main import app
import modal
from main import app

stub = modal.Stub("rag-citation")

Expand Down
1 change: 1 addition & 0 deletions examples/citations/run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional

from openai import OpenAI
from pydantic import (
BaseModel,
Expand Down
5 changes: 3 additions & 2 deletions examples/classification/classifiy_with_validation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# pip install openai instructor
from pydantic import BaseModel, field_validator, Field
import openai
import instructor
from pydantic import BaseModel, Field, field_validator
from tqdm import tqdm

import instructor

client = instructor.from_openai(openai.OpenAI())

classes = {
Expand Down
3 changes: 2 additions & 1 deletion examples/classification/multi_prediction.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import enum
import instructor

from openai import OpenAI
from pydantic import BaseModel

import instructor

client = instructor.from_openai(OpenAI())


Expand Down
5 changes: 3 additions & 2 deletions examples/classification/simple_prediction.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import enum
import instructor
from openai import OpenAI

from openai import OpenAI
from pydantic import BaseModel

import instructor

client = instructor.from_openai(OpenAI())


Expand Down
7 changes: 4 additions & 3 deletions examples/codegen-from-schema/create_fastapi_app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import json
import datetime
from pathlib import Path
from jinja2 import Template
import json
import re
from pathlib import Path

from datamodel_code_generator import InputFileType, generate
from jinja2 import Template
from pydantic import BaseModel

APP_TEMPLATE_STR = '''# generated by instructor-codegen:
Expand Down
6 changes: 3 additions & 3 deletions examples/codegen-from-schema/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
# api_path: /api/v1/extract_person
# json_schema_path: ./input.json

import instructor

from fastapi import FastAPI
from pydantic import BaseModel
from jinja2 import Template
from models import ExtractPerson
from openai import AsyncOpenAI
from pydantic import BaseModel

import instructor

aclient = instructor.apatch(AsyncOpenAI())

Expand Down
2 changes: 1 addition & 1 deletion examples/cohere/cohere.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cohere
import instructor
from pydantic import BaseModel, Field

import instructor

# Patching the Cohere client with the instructor for enhanced capabilities
client = instructor.from_cohere(
Expand Down
4 changes: 3 additions & 1 deletion examples/crm/run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from enum import Enum

from openai import OpenAI
from pydantic import BaseModel, Field

import instructor
from openai import OpenAI

client = instructor.from_openai(OpenAI())

Expand Down
1 change: 1 addition & 0 deletions examples/distilations/three_digit_mul.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from pydantic import BaseModel, Field

from instructor import Instructions

logging.basicConfig(level=logging.INFO)
Expand Down
3 changes: 2 additions & 1 deletion examples/distilations/three_digit_mul_dispatch.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging

from pydantic import BaseModel, Field
from instructor import Instructions

import instructor
from instructor import Instructions

instructor.from_openai()

Expand Down
7 changes: 4 additions & 3 deletions examples/evals/eval.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import json
from collections import Counter, defaultdict
from enum import Enum
from pprint import pprint
from typing import Any, Union

import models as m
import numpy as np
import json
from pydantic import ValidationError
from pprint import pprint
import models as m


class Status(Enum):
Expand Down
3 changes: 2 additions & 1 deletion examples/evals/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from enum import Enum
from typing import Optional

from pydantic import BaseModel, Field
from enum import Enum


class SourceType(str, Enum):
Expand Down
10 changes: 6 additions & 4 deletions examples/extract-table/run_vision.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from openai import OpenAI
from io import StringIO
from typing import Annotated, Any

import pandas as pd
from openai import OpenAI
from pydantic import (
BaseModel,
BeforeValidator,
PlainSerializer,
InstanceOf,
PlainSerializer,
WithJsonSchema,
)
import instructor
import pandas as pd
from rich.console import Console

import instructor

console = Console()
client = instructor.from_openai(
client=OpenAI(),
Expand Down