|
1 | 1 | from datafast.llms import OpenRouterProvider |
2 | 2 | from dotenv import load_dotenv |
3 | 3 | import pytest |
4 | | -from typing import List, Optional |
5 | | -from pydantic import BaseModel, Field, field_validator |
| 4 | +from tests.test_schemas import ( |
| 5 | + SimpleResponse, |
| 6 | + LandmarkInfo, |
| 7 | + PersonaContent, |
| 8 | + QASet, |
| 9 | + MCQSet, |
| 10 | +) |
6 | 11 |
|
7 | 12 | load_dotenv() |
8 | 13 |
|
9 | 14 |
|
10 | | -class SimpleResponse(BaseModel): |
11 | | - """Simple response model for testing structured output.""" |
12 | | - answer: str = Field(description="The answer to the question") |
13 | | - reasoning: str = Field(description="The reasoning behind the answer") |
14 | | - |
15 | | - |
16 | | -class Attribute(BaseModel): |
17 | | - """Attribute of a landmark with value and importance.""" |
18 | | - name: str = Field(description="Name of the attribute") |
19 | | - value: str = Field(description="Value of the attribute") |
20 | | - importance: float = Field(description="Importance score between 0 and 1") |
21 | | - |
22 | | - @field_validator('importance') |
23 | | - def check_importance(cls, v: float) -> float: |
24 | | - """Validate importance is between 0 and 1.""" |
25 | | - if not 0 <= v <= 1: |
26 | | - raise ValueError("Importance must be between 0 and 1") |
27 | | - return v |
28 | | - |
29 | | - |
30 | | -class LandmarkInfo(BaseModel): |
31 | | - """Information about a landmark with attributes.""" |
32 | | - name: str = Field(description="The name of the landmark") |
33 | | - location: str = Field(description="Where the landmark is located") |
34 | | - description: str = Field(description="A brief description of the landmark") |
35 | | - year_built: Optional[int] = Field( |
36 | | - None, description="Year when the landmark was built") |
37 | | - attributes: List[Attribute] = Field( |
38 | | - description="List of attributes about the landmark") |
39 | | - visitor_rating: float = Field( |
40 | | - description="Average visitor rating from 0 to 5") |
41 | | - |
42 | | - @field_validator('visitor_rating') |
43 | | - def check_rating(cls, v: float) -> float: |
44 | | - """Validate rating is between 0 and 5.""" |
45 | | - if not 0 <= v <= 5: |
46 | | - raise ValueError("Rating must be between 0 and 5") |
47 | | - return v |
48 | | - |
49 | | - |
50 | | -class PersonaContent(BaseModel): |
51 | | - """Generated content for a persona including tweets and bio.""" |
52 | | - tweets: List[str] = Field(description="List of 5 tweets for the persona") |
53 | | - bio: str = Field(description="Biography for the persona") |
54 | | - |
55 | | - @field_validator('tweets') |
56 | | - def check_tweets_count(cls, v: List[str]) -> List[str]: |
57 | | - """Validate that exactly 5 tweets are provided.""" |
58 | | - if len(v) != 5: |
59 | | - raise ValueError("Must provide exactly 5 tweets") |
60 | | - return v |
61 | | - |
62 | | - |
63 | | -class QAItem(BaseModel): |
64 | | - """Question and answer pair.""" |
65 | | - question: str = Field(description="The question") |
66 | | - answer: str = Field(description="The correct answer") |
67 | | - |
68 | | - |
69 | | -class QASet(BaseModel): |
70 | | - """Set of questions and answers.""" |
71 | | - questions: List[QAItem] = Field(description="List of question-answer pairs") |
72 | | - |
73 | | - @field_validator('questions') |
74 | | - def check_qa_count(cls, v: List[QAItem]) -> List[QAItem]: |
75 | | - """Validate that exactly 5 Q&A pairs are provided.""" |
76 | | - if len(v) != 5: |
77 | | - raise ValueError("Must provide exactly 5 question-answer pairs") |
78 | | - return v |
79 | | - |
80 | | - |
81 | | -class MCQQuestion(BaseModel): |
82 | | - """Multiple choice question with one correct and three incorrect answers.""" |
83 | | - question: str = Field(description="The question") |
84 | | - correct_answer: str = Field(description="The correct answer") |
85 | | - incorrect_answers: List[str] = Field(description="List of 3 incorrect answers") |
86 | | - |
87 | | - @field_validator('incorrect_answers') |
88 | | - def check_incorrect_count(cls, v: List[str]) -> List[str]: |
89 | | - """Validate that exactly 3 incorrect answers are provided.""" |
90 | | - if len(v) != 3: |
91 | | - raise ValueError("Must provide exactly 3 incorrect answers") |
92 | | - return v |
93 | | - |
94 | | - |
95 | | -class MCQSet(BaseModel): |
96 | | - """Set of multiple choice questions.""" |
97 | | - questions: List[MCQQuestion] = Field(description="List of MCQ questions") |
98 | | - |
99 | | - @field_validator('questions') |
100 | | - def check_questions_count(cls, v: List[MCQQuestion]) -> List[MCQQuestion]: |
101 | | - """Validate that exactly 3 questions are provided.""" |
102 | | - if len(v) != 3: |
103 | | - raise ValueError("Must provide exactly 3 questions") |
104 | | - return v |
105 | | - |
106 | | - |
107 | 15 | @pytest.mark.integration |
108 | 16 | class TestOpenRouterProvider: |
109 | 17 | """Test suite for OpenRouter provider with various input types and configurations.""" |
|
0 commit comments