airtrain 0.1.10__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- airtrain/__init__.py +9 -0
- airtrain/core/__init__.py +7 -0
- airtrain/core/credentials.py +125 -0
- airtrain/core/schemas.py +237 -0
- airtrain/core/skills.py +167 -0
- airtrain/integrations/__init__.py +47 -0
- airtrain/integrations/anthropic/__init__.py +11 -0
- airtrain/integrations/anthropic/credentials.py +32 -0
- airtrain/integrations/anthropic/skills.py +135 -0
- airtrain/integrations/aws/__init__.py +6 -0
- airtrain/integrations/aws/credentials.py +36 -0
- airtrain/integrations/aws/skills.py +98 -0
- airtrain/integrations/cerebras/__init__.py +6 -0
- airtrain/integrations/cerebras/credentials.py +22 -0
- airtrain/integrations/cerebras/skills.py +41 -0
- airtrain/integrations/google/__init__.py +6 -0
- airtrain/integrations/google/credentials.py +27 -0
- airtrain/integrations/google/skills.py +41 -0
- airtrain/integrations/groq/__init__.py +6 -0
- airtrain/integrations/groq/credentials.py +24 -0
- airtrain/integrations/groq/skills.py +41 -0
- airtrain/integrations/ollama/__init__.py +6 -0
- airtrain/integrations/ollama/credentials.py +26 -0
- airtrain/integrations/ollama/skills.py +41 -0
- airtrain/integrations/openai/__init__.py +19 -0
- airtrain/integrations/openai/chinese_assistant.py +42 -0
- airtrain/integrations/openai/credentials.py +39 -0
- airtrain/integrations/openai/skills.py +208 -0
- airtrain/integrations/sambanova/__init__.py +6 -0
- airtrain/integrations/sambanova/credentials.py +20 -0
- airtrain/integrations/sambanova/skills.py +41 -0
- airtrain/integrations/together/__init__.py +6 -0
- airtrain/integrations/together/credentials.py +22 -0
- airtrain/integrations/together/skills.py +43 -0
- airtrain-0.1.10.dist-info/METADATA +168 -0
- airtrain-0.1.10.dist-info/RECORD +38 -0
- airtrain-0.1.10.dist-info/WHEEL +5 -0
- airtrain-0.1.10.dist-info/top_level.txt +1 -0
@@ -0,0 +1,135 @@
|
|
1
|
+
from typing import List, Optional, Dict, Any
|
2
|
+
from pydantic import Field
|
3
|
+
from anthropic import Anthropic
|
4
|
+
import base64
|
5
|
+
from pathlib import Path
|
6
|
+
from loguru import logger
|
7
|
+
|
8
|
+
from airtrain.core.skills import Skill, ProcessingError
|
9
|
+
from airtrain.core.schemas import InputSchema, OutputSchema
|
10
|
+
from .credentials import AnthropicCredentials
|
11
|
+
|
12
|
+
|
13
|
+
class AnthropicInput(InputSchema):
|
14
|
+
"""Schema for Anthropic chat input"""
|
15
|
+
|
16
|
+
user_input: str = Field(..., description="User's input text")
|
17
|
+
system_prompt: str = Field(
|
18
|
+
default="You are a helpful assistant.",
|
19
|
+
description="System prompt to guide the model's behavior",
|
20
|
+
)
|
21
|
+
model: str = Field(
|
22
|
+
default="claude-3-opus-20240229", description="Anthropic model to use"
|
23
|
+
)
|
24
|
+
max_tokens: int = Field(default=1024, description="Maximum tokens in response")
|
25
|
+
temperature: float = Field(
|
26
|
+
default=0.7, description="Temperature for response generation", ge=0, le=1
|
27
|
+
)
|
28
|
+
images: Optional[List[Path]] = Field(
|
29
|
+
default=None,
|
30
|
+
description="Optional list of image paths to include in the message",
|
31
|
+
)
|
32
|
+
|
33
|
+
|
34
|
+
class AnthropicOutput(OutputSchema):
|
35
|
+
"""Schema for Anthropic chat output"""
|
36
|
+
|
37
|
+
response: str = Field(..., description="Model's response text")
|
38
|
+
used_model: str = Field(..., description="Model used for generation")
|
39
|
+
usage: Dict[str, Any] = Field(
|
40
|
+
default_factory=dict, description="Usage statistics from the API"
|
41
|
+
)
|
42
|
+
|
43
|
+
|
44
|
+
class AnthropicChatSkill(Skill[AnthropicInput, AnthropicOutput]):
|
45
|
+
"""Skill for interacting with Anthropic's Claude models"""
|
46
|
+
|
47
|
+
input_schema = AnthropicInput
|
48
|
+
output_schema = AnthropicOutput
|
49
|
+
|
50
|
+
def __init__(self, credentials: Optional[AnthropicCredentials] = None):
|
51
|
+
"""Initialize the skill with optional credentials"""
|
52
|
+
super().__init__()
|
53
|
+
self.credentials = credentials or AnthropicCredentials.from_env()
|
54
|
+
self.client = Anthropic(
|
55
|
+
api_key=self.credentials.anthropic_api_key.get_secret_value()
|
56
|
+
)
|
57
|
+
|
58
|
+
def _encode_image(self, image_path: Path) -> Dict[str, Any]:
|
59
|
+
"""Convert image to base64 for API consumption"""
|
60
|
+
try:
|
61
|
+
if not image_path.exists():
|
62
|
+
raise FileNotFoundError(f"Image file not found: {image_path}")
|
63
|
+
|
64
|
+
with open(image_path, "rb") as img_file:
|
65
|
+
encoded = base64.b64encode(img_file.read()).decode()
|
66
|
+
return {
|
67
|
+
"type": "image",
|
68
|
+
"source": {
|
69
|
+
"type": "base64",
|
70
|
+
"media_type": f"image/{image_path.suffix[1:]}",
|
71
|
+
"data": encoded,
|
72
|
+
},
|
73
|
+
}
|
74
|
+
except Exception as e:
|
75
|
+
logger.error(f"Failed to encode image {image_path}: {str(e)}")
|
76
|
+
raise ProcessingError(f"Image encoding failed: {str(e)}")
|
77
|
+
|
78
|
+
def process(self, input_data: AnthropicInput) -> AnthropicOutput:
|
79
|
+
"""Process the input using Anthropic's API"""
|
80
|
+
try:
|
81
|
+
logger.info(f"Processing request with model {input_data.model}")
|
82
|
+
|
83
|
+
# Prepare message content
|
84
|
+
content = []
|
85
|
+
|
86
|
+
# Add text content
|
87
|
+
content.append({"type": "text", "text": input_data.user_input})
|
88
|
+
|
89
|
+
# Add images if provided
|
90
|
+
if input_data.images:
|
91
|
+
logger.debug(f"Processing {len(input_data.images)} images")
|
92
|
+
for image_path in input_data.images:
|
93
|
+
content.append(self._encode_image(image_path))
|
94
|
+
|
95
|
+
# Create message
|
96
|
+
response = self.client.messages.create(
|
97
|
+
model=input_data.model,
|
98
|
+
max_tokens=input_data.max_tokens,
|
99
|
+
temperature=input_data.temperature,
|
100
|
+
system=input_data.system_prompt,
|
101
|
+
messages=[{"role": "user", "content": content}],
|
102
|
+
)
|
103
|
+
|
104
|
+
# Validate response content
|
105
|
+
if not response.content:
|
106
|
+
logger.error("Empty response received from Anthropic API")
|
107
|
+
raise ProcessingError("Empty response received from Anthropic API")
|
108
|
+
|
109
|
+
if not isinstance(response.content, list) or not response.content:
|
110
|
+
logger.error("Invalid response format from Anthropic API")
|
111
|
+
raise ProcessingError("Invalid response format from Anthropic API")
|
112
|
+
|
113
|
+
first_content = response.content[0]
|
114
|
+
if not hasattr(first_content, "text"):
|
115
|
+
logger.error("Response content does not contain text")
|
116
|
+
raise ProcessingError("Response content does not contain text")
|
117
|
+
|
118
|
+
logger.success("Successfully processed Anthropic request")
|
119
|
+
|
120
|
+
# Create output
|
121
|
+
return AnthropicOutput(
|
122
|
+
response=first_content.text,
|
123
|
+
used_model=response.model,
|
124
|
+
usage={
|
125
|
+
"input_tokens": response.usage.input_tokens,
|
126
|
+
"output_tokens": response.usage.output_tokens,
|
127
|
+
},
|
128
|
+
)
|
129
|
+
|
130
|
+
except ProcessingError:
|
131
|
+
# Re-raise ProcessingError without modification
|
132
|
+
raise
|
133
|
+
except Exception as e:
|
134
|
+
logger.exception(f"Anthropic processing failed: {str(e)}")
|
135
|
+
raise ProcessingError(f"Anthropic processing failed: {str(e)}")
|
@@ -0,0 +1,36 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
from pydantic import Field, SecretStr
|
3
|
+
from airtrain.core.credentials import BaseCredentials, CredentialValidationError
|
4
|
+
import boto3
|
5
|
+
|
6
|
+
|
7
|
+
class AWSCredentials(BaseCredentials):
|
8
|
+
"""AWS credentials"""
|
9
|
+
|
10
|
+
aws_access_key_id: SecretStr = Field(..., description="AWS Access Key ID")
|
11
|
+
aws_secret_access_key: SecretStr = Field(..., description="AWS Secret Access Key")
|
12
|
+
aws_region: str = Field(default="us-east-1", description="AWS Region")
|
13
|
+
aws_session_token: Optional[SecretStr] = Field(
|
14
|
+
None, description="AWS Session Token"
|
15
|
+
)
|
16
|
+
|
17
|
+
_required_credentials = {"aws_access_key_id", "aws_secret_access_key"}
|
18
|
+
|
19
|
+
async def validate_credentials(self) -> bool:
|
20
|
+
"""Validate AWS credentials by making a test API call"""
|
21
|
+
try:
|
22
|
+
session = boto3.Session(
|
23
|
+
aws_access_key_id=self.aws_access_key_id.get_secret_value(),
|
24
|
+
aws_secret_access_key=self.aws_secret_access_key.get_secret_value(),
|
25
|
+
aws_session_token=(
|
26
|
+
self.aws_session_token.get_secret_value()
|
27
|
+
if self.aws_session_token
|
28
|
+
else None
|
29
|
+
),
|
30
|
+
region_name=self.aws_region,
|
31
|
+
)
|
32
|
+
sts = session.client("sts")
|
33
|
+
sts.get_caller_identity()
|
34
|
+
return True
|
35
|
+
except Exception as e:
|
36
|
+
raise CredentialValidationError(f"Invalid AWS credentials: {str(e)}")
|
@@ -0,0 +1,98 @@
|
|
1
|
+
from typing import List, Optional, Dict, Any
|
2
|
+
from pydantic import Field
|
3
|
+
import boto3
|
4
|
+
from pathlib import Path
|
5
|
+
from loguru import logger
|
6
|
+
|
7
|
+
from airtrain.core.skills import Skill, ProcessingError
|
8
|
+
from airtrain.core.schemas import InputSchema, OutputSchema
|
9
|
+
from .credentials import AWSCredentials
|
10
|
+
|
11
|
+
|
12
|
+
class AWSBedrockInput(InputSchema):
|
13
|
+
"""Schema for AWS Bedrock chat input"""
|
14
|
+
|
15
|
+
user_input: str = Field(..., description="User's input text")
|
16
|
+
system_prompt: str = Field(
|
17
|
+
default="You are a helpful assistant.",
|
18
|
+
description="System prompt to guide the model's behavior",
|
19
|
+
)
|
20
|
+
model: str = Field(
|
21
|
+
default="anthropic.claude-3-sonnet-20240229-v1:0",
|
22
|
+
description="AWS Bedrock model to use",
|
23
|
+
)
|
24
|
+
max_tokens: int = Field(default=1024, description="Maximum tokens in response")
|
25
|
+
temperature: float = Field(
|
26
|
+
default=0.7, description="Temperature for response generation", ge=0, le=1
|
27
|
+
)
|
28
|
+
images: Optional[List[Path]] = Field(
|
29
|
+
default=None,
|
30
|
+
description="Optional list of image paths to include in the message",
|
31
|
+
)
|
32
|
+
|
33
|
+
|
34
|
+
class AWSBedrockOutput(OutputSchema):
|
35
|
+
"""Schema for AWS Bedrock chat output"""
|
36
|
+
|
37
|
+
response: str = Field(..., description="Model's response text")
|
38
|
+
used_model: str = Field(..., description="Model used for generation")
|
39
|
+
usage: Dict[str, Any] = Field(
|
40
|
+
default_factory=dict, description="Usage statistics from the API"
|
41
|
+
)
|
42
|
+
|
43
|
+
|
44
|
+
class AWSBedrockSkill(Skill[AWSBedrockInput, AWSBedrockOutput]):
|
45
|
+
"""Skill for interacting with AWS Bedrock models"""
|
46
|
+
|
47
|
+
input_schema = AWSBedrockInput
|
48
|
+
output_schema = AWSBedrockOutput
|
49
|
+
|
50
|
+
def __init__(self, credentials: Optional[AWSCredentials] = None):
|
51
|
+
"""Initialize the skill with optional credentials"""
|
52
|
+
super().__init__()
|
53
|
+
self.credentials = credentials or AWSCredentials.from_env()
|
54
|
+
self.client = boto3.client(
|
55
|
+
"bedrock-runtime",
|
56
|
+
aws_access_key_id=self.credentials.aws_access_key_id.get_secret_value(),
|
57
|
+
aws_secret_access_key=self.credentials.aws_secret_access_key.get_secret_value(),
|
58
|
+
region_name=self.credentials.aws_region,
|
59
|
+
)
|
60
|
+
|
61
|
+
def process(self, input_data: AWSBedrockInput) -> AWSBedrockOutput:
|
62
|
+
"""Process the input using AWS Bedrock API"""
|
63
|
+
try:
|
64
|
+
logger.info(f"Processing request with model {input_data.model}")
|
65
|
+
|
66
|
+
# Prepare request body based on model provider
|
67
|
+
if "anthropic" in input_data.model:
|
68
|
+
request_body = {
|
69
|
+
"anthropic_version": "bedrock-2023-05-31",
|
70
|
+
"max_tokens": input_data.max_tokens,
|
71
|
+
"temperature": input_data.temperature,
|
72
|
+
"system": input_data.system_prompt,
|
73
|
+
"messages": [{"role": "user", "content": input_data.user_input}],
|
74
|
+
}
|
75
|
+
else:
|
76
|
+
raise ProcessingError(f"Unsupported model: {input_data.model}")
|
77
|
+
|
78
|
+
response = self.client.invoke_model(
|
79
|
+
modelId=input_data.model, body=request_body
|
80
|
+
)
|
81
|
+
|
82
|
+
# Parse response based on model provider
|
83
|
+
if "anthropic" in input_data.model:
|
84
|
+
response_data = response["body"]["completion"]
|
85
|
+
usage = {
|
86
|
+
"input_tokens": response["body"]["usage"]["input_tokens"],
|
87
|
+
"output_tokens": response["body"]["usage"]["output_tokens"],
|
88
|
+
}
|
89
|
+
else:
|
90
|
+
raise ProcessingError(f"Unsupported model response: {input_data.model}")
|
91
|
+
|
92
|
+
return AWSBedrockOutput(
|
93
|
+
response=response_data, used_model=input_data.model, usage=usage
|
94
|
+
)
|
95
|
+
|
96
|
+
except Exception as e:
|
97
|
+
logger.exception(f"AWS Bedrock processing failed: {str(e)}")
|
98
|
+
raise ProcessingError(f"AWS Bedrock processing failed: {str(e)}")
|
@@ -0,0 +1,22 @@
|
|
1
|
+
from pydantic import Field, SecretStr, HttpUrl
|
2
|
+
from airtrain.core.credentials import BaseCredentials, CredentialValidationError
|
3
|
+
from typing import Optional
|
4
|
+
|
5
|
+
|
6
|
+
class CerebrasCredentials(BaseCredentials):
|
7
|
+
"""Cerebras credentials"""
|
8
|
+
|
9
|
+
api_key: SecretStr = Field(..., description="Cerebras API key")
|
10
|
+
endpoint_url: HttpUrl = Field(..., description="Cerebras API endpoint")
|
11
|
+
project_id: Optional[str] = Field(None, description="Cerebras Project ID")
|
12
|
+
|
13
|
+
_required_credentials = {"api_key", "endpoint_url"}
|
14
|
+
|
15
|
+
async def validate_credentials(self) -> bool:
|
16
|
+
"""Validate Cerebras credentials"""
|
17
|
+
try:
|
18
|
+
# Implement Cerebras-specific validation
|
19
|
+
# This would depend on their API client implementation
|
20
|
+
return True
|
21
|
+
except Exception as e:
|
22
|
+
raise CredentialValidationError(f"Invalid Cerebras credentials: {str(e)}")
|
@@ -0,0 +1,41 @@
|
|
1
|
+
from typing import Optional, Dict, Any
|
2
|
+
from pydantic import Field
|
3
|
+
from airtrain.core.skills import Skill, ProcessingError
|
4
|
+
from airtrain.core.schemas import InputSchema, OutputSchema
|
5
|
+
from .credentials import CerebrasCredentials
|
6
|
+
|
7
|
+
|
8
|
+
class CerebrasInput(InputSchema):
|
9
|
+
"""Schema for Cerebras input"""
|
10
|
+
|
11
|
+
user_input: str = Field(..., description="User's input text")
|
12
|
+
system_prompt: str = Field(
|
13
|
+
default="You are a helpful assistant.",
|
14
|
+
description="System prompt to guide the model's behavior",
|
15
|
+
)
|
16
|
+
model: str = Field(default="cerebras-gpt", description="Cerebras model to use")
|
17
|
+
max_tokens: int = Field(default=1024, description="Maximum tokens in response")
|
18
|
+
temperature: float = Field(
|
19
|
+
default=0.7, description="Temperature for response generation", ge=0, le=1
|
20
|
+
)
|
21
|
+
|
22
|
+
|
23
|
+
class CerebrasOutput(OutputSchema):
|
24
|
+
"""Schema for Cerebras output"""
|
25
|
+
|
26
|
+
response: str = Field(..., description="Model's response text")
|
27
|
+
used_model: str = Field(..., description="Model used for generation")
|
28
|
+
usage: Dict[str, Any] = Field(default_factory=dict, description="Usage statistics")
|
29
|
+
|
30
|
+
|
31
|
+
class CerebrasChatSkill(Skill[CerebrasInput, CerebrasOutput]):
|
32
|
+
"""Skill for Cerebras - Not Implemented"""
|
33
|
+
|
34
|
+
input_schema = CerebrasInput
|
35
|
+
output_schema = CerebrasOutput
|
36
|
+
|
37
|
+
def __init__(self, credentials: Optional[CerebrasCredentials] = None):
|
38
|
+
raise NotImplementedError("CerebrasChatSkill is not implemented yet")
|
39
|
+
|
40
|
+
def process(self, input_data: CerebrasInput) -> CerebrasOutput:
|
41
|
+
raise NotImplementedError("CerebrasChatSkill is not implemented yet")
|
@@ -0,0 +1,27 @@
|
|
1
|
+
from pydantic import Field, SecretStr
|
2
|
+
from airtrain.core.credentials import BaseCredentials, CredentialValidationError
|
3
|
+
from google.cloud import storage
|
4
|
+
|
5
|
+
|
6
|
+
class GoogleCloudCredentials(BaseCredentials):
|
7
|
+
"""Google Cloud credentials"""
|
8
|
+
|
9
|
+
project_id: str = Field(..., description="Google Cloud Project ID")
|
10
|
+
service_account_key: SecretStr = Field(..., description="Service Account Key JSON")
|
11
|
+
|
12
|
+
_required_credentials = {"project_id", "service_account_key"}
|
13
|
+
|
14
|
+
async def validate_credentials(self) -> bool:
|
15
|
+
"""Validate Google Cloud credentials"""
|
16
|
+
try:
|
17
|
+
# Initialize with service account key
|
18
|
+
storage_client = storage.Client.from_service_account_info(
|
19
|
+
self.service_account_key.get_secret_value()
|
20
|
+
)
|
21
|
+
# Test API call
|
22
|
+
storage_client.list_buckets(max_results=1)
|
23
|
+
return True
|
24
|
+
except Exception as e:
|
25
|
+
raise CredentialValidationError(
|
26
|
+
f"Invalid Google Cloud credentials: {str(e)}"
|
27
|
+
)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
from typing import Optional, Dict, Any
|
2
|
+
from pydantic import Field
|
3
|
+
from airtrain.core.skills import Skill, ProcessingError
|
4
|
+
from airtrain.core.schemas import InputSchema, OutputSchema
|
5
|
+
from .credentials import GoogleCloudCredentials
|
6
|
+
|
7
|
+
|
8
|
+
class VertexAIInput(InputSchema):
|
9
|
+
"""Schema for Google Vertex AI input"""
|
10
|
+
|
11
|
+
user_input: str = Field(..., description="User's input text")
|
12
|
+
system_prompt: str = Field(
|
13
|
+
default="You are a helpful assistant.",
|
14
|
+
description="System prompt to guide the model's behavior",
|
15
|
+
)
|
16
|
+
model: str = Field(default="text-bison", description="Vertex AI model to use")
|
17
|
+
max_tokens: int = Field(default=1024, description="Maximum tokens in response")
|
18
|
+
temperature: float = Field(
|
19
|
+
default=0.7, description="Temperature for response generation", ge=0, le=1
|
20
|
+
)
|
21
|
+
|
22
|
+
|
23
|
+
class VertexAIOutput(OutputSchema):
|
24
|
+
"""Schema for Vertex AI output"""
|
25
|
+
|
26
|
+
response: str = Field(..., description="Model's response text")
|
27
|
+
used_model: str = Field(..., description="Model used for generation")
|
28
|
+
usage: Dict[str, Any] = Field(default_factory=dict, description="Usage statistics")
|
29
|
+
|
30
|
+
|
31
|
+
class VertexAISkill(Skill[VertexAIInput, VertexAIOutput]):
|
32
|
+
"""Skill for Google Vertex AI - Not Implemented"""
|
33
|
+
|
34
|
+
input_schema = VertexAIInput
|
35
|
+
output_schema = VertexAIOutput
|
36
|
+
|
37
|
+
def __init__(self, credentials: Optional[GoogleCloudCredentials] = None):
|
38
|
+
raise NotImplementedError("VertexAISkill is not implemented yet")
|
39
|
+
|
40
|
+
def process(self, input_data: VertexAIInput) -> VertexAIOutput:
|
41
|
+
raise NotImplementedError("VertexAISkill is not implemented yet")
|
@@ -0,0 +1,24 @@
|
|
1
|
+
from pydantic import Field, SecretStr
|
2
|
+
from airtrain.core.credentials import BaseCredentials, CredentialValidationError
|
3
|
+
from groq import Groq
|
4
|
+
|
5
|
+
|
6
|
+
class GroqCredentials(BaseCredentials):
|
7
|
+
"""Groq API credentials"""
|
8
|
+
|
9
|
+
api_key: SecretStr = Field(..., description="Groq API key")
|
10
|
+
|
11
|
+
_required_credentials = {"api_key"}
|
12
|
+
|
13
|
+
async def validate_credentials(self) -> bool:
|
14
|
+
"""Validate Groq credentials"""
|
15
|
+
try:
|
16
|
+
client = Groq(api_key=self.api_key.get_secret_value())
|
17
|
+
await client.chat.completions.create(
|
18
|
+
messages=[{"role": "user", "content": "Hi"}],
|
19
|
+
model="mixtral-8x7b-32768",
|
20
|
+
max_tokens=1,
|
21
|
+
)
|
22
|
+
return True
|
23
|
+
except Exception as e:
|
24
|
+
raise CredentialValidationError(f"Invalid Groq credentials: {str(e)}")
|
@@ -0,0 +1,41 @@
|
|
1
|
+
from typing import Optional, Dict, Any
|
2
|
+
from pydantic import Field
|
3
|
+
from airtrain.core.skills import Skill, ProcessingError
|
4
|
+
from airtrain.core.schemas import InputSchema, OutputSchema
|
5
|
+
from .credentials import GroqCredentials
|
6
|
+
|
7
|
+
|
8
|
+
class GroqInput(InputSchema):
|
9
|
+
"""Schema for Groq input"""
|
10
|
+
|
11
|
+
user_input: str = Field(..., description="User's input text")
|
12
|
+
system_prompt: str = Field(
|
13
|
+
default="You are a helpful assistant.",
|
14
|
+
description="System prompt to guide the model's behavior",
|
15
|
+
)
|
16
|
+
model: str = Field(default="mixtral-8x7b", description="Groq model to use")
|
17
|
+
max_tokens: int = Field(default=1024, description="Maximum tokens in response")
|
18
|
+
temperature: float = Field(
|
19
|
+
default=0.7, description="Temperature for response generation", ge=0, le=1
|
20
|
+
)
|
21
|
+
|
22
|
+
|
23
|
+
class GroqOutput(OutputSchema):
|
24
|
+
"""Schema for Groq output"""
|
25
|
+
|
26
|
+
response: str = Field(..., description="Model's response text")
|
27
|
+
used_model: str = Field(..., description="Model used for generation")
|
28
|
+
usage: Dict[str, Any] = Field(default_factory=dict, description="Usage statistics")
|
29
|
+
|
30
|
+
|
31
|
+
class GroqChatSkill(Skill[GroqInput, GroqOutput]):
|
32
|
+
"""Skill for Groq - Not Implemented"""
|
33
|
+
|
34
|
+
input_schema = GroqInput
|
35
|
+
output_schema = GroqOutput
|
36
|
+
|
37
|
+
def __init__(self, credentials: Optional[GroqCredentials] = None):
|
38
|
+
raise NotImplementedError("GroqChatSkill is not implemented yet")
|
39
|
+
|
40
|
+
def process(self, input_data: GroqInput) -> GroqOutput:
|
41
|
+
raise NotImplementedError("GroqChatSkill is not implemented yet")
|
@@ -0,0 +1,26 @@
|
|
1
|
+
from pydantic import Field
|
2
|
+
from airtrain.core.credentials import BaseCredentials, CredentialValidationError
|
3
|
+
from importlib.util import find_spec
|
4
|
+
|
5
|
+
|
6
|
+
class OllamaCredentials(BaseCredentials):
|
7
|
+
"""Ollama credentials"""
|
8
|
+
|
9
|
+
host: str = Field(default="http://localhost:11434", description="Ollama host URL")
|
10
|
+
timeout: int = Field(default=30, description="Request timeout in seconds")
|
11
|
+
|
12
|
+
async def validate_credentials(self) -> bool:
|
13
|
+
"""Validate Ollama credentials"""
|
14
|
+
if find_spec("ollama") is None:
|
15
|
+
raise CredentialValidationError(
|
16
|
+
"Ollama package is not installed. Please install it using: pip install ollama"
|
17
|
+
)
|
18
|
+
|
19
|
+
try:
|
20
|
+
from ollama import Client
|
21
|
+
|
22
|
+
client = Client(host=self.host)
|
23
|
+
await client.list()
|
24
|
+
return True
|
25
|
+
except Exception as e:
|
26
|
+
raise CredentialValidationError(f"Invalid Ollama connection: {str(e)}")
|
@@ -0,0 +1,41 @@
|
|
1
|
+
from typing import Optional, Dict, Any
|
2
|
+
from pydantic import Field
|
3
|
+
from airtrain.core.skills import Skill, ProcessingError
|
4
|
+
from airtrain.core.schemas import InputSchema, OutputSchema
|
5
|
+
from .credentials import OllamaCredentials
|
6
|
+
|
7
|
+
|
8
|
+
class OllamaInput(InputSchema):
|
9
|
+
"""Schema for Ollama input"""
|
10
|
+
|
11
|
+
user_input: str = Field(..., description="User's input text")
|
12
|
+
system_prompt: str = Field(
|
13
|
+
default="You are a helpful assistant.",
|
14
|
+
description="System prompt to guide the model's behavior",
|
15
|
+
)
|
16
|
+
model: str = Field(default="llama2", description="Ollama model to use")
|
17
|
+
max_tokens: int = Field(default=1024, description="Maximum tokens in response")
|
18
|
+
temperature: float = Field(
|
19
|
+
default=0.7, description="Temperature for response generation", ge=0, le=1
|
20
|
+
)
|
21
|
+
|
22
|
+
|
23
|
+
class OllamaOutput(OutputSchema):
|
24
|
+
"""Schema for Ollama output"""
|
25
|
+
|
26
|
+
response: str = Field(..., description="Model's response text")
|
27
|
+
used_model: str = Field(..., description="Model used for generation")
|
28
|
+
usage: Dict[str, Any] = Field(default_factory=dict, description="Usage statistics")
|
29
|
+
|
30
|
+
|
31
|
+
class OllamaChatSkill(Skill[OllamaInput, OllamaOutput]):
|
32
|
+
"""Skill for Ollama - Not Implemented"""
|
33
|
+
|
34
|
+
input_schema = OllamaInput
|
35
|
+
output_schema = OllamaOutput
|
36
|
+
|
37
|
+
def __init__(self, credentials: Optional[OllamaCredentials] = None):
|
38
|
+
raise NotImplementedError("OllamaChatSkill is not implemented yet")
|
39
|
+
|
40
|
+
def process(self, input_data: OllamaInput) -> OllamaOutput:
|
41
|
+
raise NotImplementedError("OllamaChatSkill is not implemented yet")
|
@@ -0,0 +1,19 @@
|
|
1
|
+
from .skills import (
|
2
|
+
OpenAIChatSkill,
|
3
|
+
OpenAIInput,
|
4
|
+
OpenAIParserSkill,
|
5
|
+
OpenAIOutput,
|
6
|
+
OpenAIParserInput,
|
7
|
+
OpenAIParserOutput,
|
8
|
+
)
|
9
|
+
from .credentials import OpenAICredentials
|
10
|
+
|
11
|
+
__all__ = [
|
12
|
+
"OpenAIChatSkill",
|
13
|
+
"OpenAIInput",
|
14
|
+
"OpenAIParserSkill",
|
15
|
+
"OpenAIParserInput",
|
16
|
+
"OpenAIParserOutput",
|
17
|
+
"OpenAICredentials",
|
18
|
+
"OpenAIOutput",
|
19
|
+
]
|
@@ -0,0 +1,42 @@
|
|
1
|
+
from typing import Optional, TypeVar
|
2
|
+
from pydantic import Field
|
3
|
+
from .skills import OpenAIChatSkill, OpenAIInput, OpenAIOutput
|
4
|
+
from .credentials import OpenAICredentials
|
5
|
+
|
6
|
+
T = TypeVar("T", bound=OpenAIInput)
|
7
|
+
|
8
|
+
|
9
|
+
class ChineseAssistantInput(OpenAIInput):
|
10
|
+
"""Schema for Chinese Assistant input"""
|
11
|
+
|
12
|
+
user_input: str = Field(
|
13
|
+
..., description="User's input text (can be in any language)"
|
14
|
+
)
|
15
|
+
system_prompt: str = Field(
|
16
|
+
default="你是一个有帮助的助手。请用中文回答所有问题,即使问题是用其他语言问的。回答要准确、礼貌、专业。",
|
17
|
+
description="System prompt in Chinese",
|
18
|
+
)
|
19
|
+
model: str = Field(default="gpt-4o", description="OpenAI model to use")
|
20
|
+
max_tokens: int = Field(default=8096, description="Maximum tokens in response")
|
21
|
+
temperature: float = Field(
|
22
|
+
default=0.7, description="Temperature for response generation", ge=0, le=1
|
23
|
+
)
|
24
|
+
|
25
|
+
|
26
|
+
class ChineseAssistantSkill(OpenAIChatSkill):
|
27
|
+
"""Skill for Chinese language assistance"""
|
28
|
+
|
29
|
+
input_schema = ChineseAssistantInput
|
30
|
+
output_schema = OpenAIOutput
|
31
|
+
|
32
|
+
def __init__(self, credentials: Optional[OpenAICredentials] = None):
|
33
|
+
super().__init__(credentials)
|
34
|
+
|
35
|
+
def process(self, input_data: T) -> OpenAIOutput:
|
36
|
+
# Add language check to ensure response is in Chinese
|
37
|
+
if "你是" not in input_data.system_prompt:
|
38
|
+
input_data.system_prompt = (
|
39
|
+
"你是一个中文助手。" + input_data.system_prompt + "请用中文回答。"
|
40
|
+
)
|
41
|
+
|
42
|
+
return super().process(input_data)
|