Spaces:
Runtime error
Runtime error
Carlos Salgado
commited on
Commit
•
9e88eab
1
Parent(s):
0c2a143
add pydantic schema, together example, gitignore
Browse files- .gitignore +5 -1
- schema.py +130 -0
- together_call.py +44 -0
.gitignore
CHANGED
@@ -1,3 +1,7 @@
|
|
1 |
.envrc
|
2 |
.direnv/
|
3 |
-
flake
|
|
|
|
|
|
|
|
|
|
1 |
.envrc
|
2 |
.direnv/
|
3 |
+
flake.lock
|
4 |
+
flake.nix
|
5 |
+
.env
|
6 |
+
.venv
|
7 |
+
|
schema.py
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
from typing import List, Optional
|
4 |
+
from pydantic import BaseModel, Field
|
5 |
+
from enum import Enum
|
6 |
+
|
7 |
+
class BimDiscipline(Enum):
|
8 |
+
plumbing = 'S - Sanitär'
|
9 |
+
network = 'd - Datennetz'
|
10 |
+
heating = 'h - Heizung'
|
11 |
+
electrical = 'e - Elektro'
|
12 |
+
ventilation = 'l - Lüftung'
|
13 |
+
architecture = 'a - Architektur'
|
14 |
+
|
15 |
+
class KeywordChoice(str, Enum):
|
16 |
+
three_dimensional_modeling = "3d modeling"
|
17 |
+
four_dimensional_simulation = "4d simulation"
|
18 |
+
five_dimensional_cost_estimation = "5d cost estimation"
|
19 |
+
six_dimensional_lifecycle_management = "6d lifecycle management"
|
20 |
+
adoption = "adoptions"
|
21 |
+
agile_bim = "agile bim"
|
22 |
+
artificial_intelligence = "artificial intelligence"
|
23 |
+
automated_code_checking = "automated code checking"
|
24 |
+
automation = "automation"
|
25 |
+
big_data_analytics = "big data analytics"
|
26 |
+
bim_based_estimating = "bim-based estimating"
|
27 |
+
bim_execution_plan = "bim execution plan"
|
28 |
+
bim_governance = "bim governance"
|
29 |
+
bim_integration = "bim integration"
|
30 |
+
bim_maturity = "bim maturity"
|
31 |
+
bim_objects = "bim objects"
|
32 |
+
bim_process = "bim process"
|
33 |
+
bim_quality_assurance = "bim quality assurance"
|
34 |
+
bim_requirements = "bim requirements"
|
35 |
+
bim_server = "bim server"
|
36 |
+
bim_standardization = "bim standardization"
|
37 |
+
bim_strategy = "bim strategy"
|
38 |
+
bim_tools = "bim tools"
|
39 |
+
bim_training = "bim training"
|
40 |
+
barriers = "barriers"
|
41 |
+
benchmarking = "benchmarking"
|
42 |
+
building_energy_modeling = "building energy modeling"
|
43 |
+
building_life_cycle = "building life cycle"
|
44 |
+
building_physics = "building physics"
|
45 |
+
building_smartness = "building smartness"
|
46 |
+
built_environment = "built environment"
|
47 |
+
case_studies = "case studies"
|
48 |
+
cloud_computing = "cloud computing"
|
49 |
+
collaborative_environments = "collaborative environments"
|
50 |
+
communication = "communication"
|
51 |
+
computational_design = "computational design"
|
52 |
+
cobie = "construction operations building information exchange"
|
53 |
+
construction_scheduling = "construction scheduling"
|
54 |
+
construction_site_layout = "construction site layout"
|
55 |
+
context_awareness = "context awareness"
|
56 |
+
contractual_issues = "contractual issues"
|
57 |
+
cost_control = "cost control"
|
58 |
+
critical_success_factors = "critical success factors"
|
59 |
+
digital_fabrication = "digital fabrication"
|
60 |
+
digital_twin = "digital twin"
|
61 |
+
disaster_response = "disaster response"
|
62 |
+
dispute_resolution = "dispute resolution"
|
63 |
+
dynamic_scheduling = "dynamic scheduling"
|
64 |
+
education = "education"
|
65 |
+
electronic_tendering = "electronic tendering"
|
66 |
+
empirical_research = "empirical research"
|
67 |
+
energy_analysis = "energy analysis"
|
68 |
+
environmental_impacts = "environmental impacts"
|
69 |
+
facility_management = "facility management"
|
70 |
+
fire_safety = "fire safety"
|
71 |
+
gis_integration = "gis integration"
|
72 |
+
green_buildings = "green buildings"
|
73 |
+
health_and_safety = "health and safety"
|
74 |
+
historical_preservation = "historical preservation"
|
75 |
+
human_behavior = "human behavior"
|
76 |
+
industrialized_construction = "industrialized construction"
|
77 |
+
information_management = "information management"
|
78 |
+
infrastructure_asset_management = "infrastructure asset management"
|
79 |
+
interoperability = "interoperability"
|
80 |
+
iot_integration = "iot integration"
|
81 |
+
knowledge_sharing = "knowledge sharing"
|
82 |
+
lean_construction = "lean construction"
|
83 |
+
legal_frameworks = "legal frameworks"
|
84 |
+
level_of_development = "level of development"
|
85 |
+
level_of_detail = "level of detail"
|
86 |
+
level_of_information_need = "level of information need"
|
87 |
+
lifetime_costs = "lifetime costs"
|
88 |
+
linked_data = "linked data"
|
89 |
+
machine_learning = "machine learning"
|
90 |
+
manufacturing = "manufacturing"
|
91 |
+
materials_management = "materials management"
|
92 |
+
mobile_applications = "mobile applications"
|
93 |
+
multi_criteria_decision_making = "multi-criteria decision making"
|
94 |
+
natural_language_processing = "natural language processing"
|
95 |
+
networking = "networking"
|
96 |
+
open_bim = "open bim"
|
97 |
+
organizational_change = "organizational change"
|
98 |
+
owner_involvement = "owner involvement"
|
99 |
+
parametric_design = "parametric design"
|
100 |
+
performance_measurement = "performance measurement"
|
101 |
+
pipeline_simulation = "pipeline simulation"
|
102 |
+
policy_implications = "policy implications"
|
103 |
+
predictive_maintenance = "predictive maintenance"
|
104 |
+
product_data_templates = "product data templates"
|
105 |
+
public_procurement = "public procurement"
|
106 |
+
radio_frequency_identification = "radio frequency identification"
|
107 |
+
reality_capture = "reality capture"
|
108 |
+
real_time_monitoring = "real-time monitoring"
|
109 |
+
reliability_engineering = "reliability engineering"
|
110 |
+
resilience = "resilience"
|
111 |
+
return_on_investment = "return on investment"
|
112 |
+
reverse_logistics = "reverse logistics"
|
113 |
+
risk_assessment = "risk assessment"
|
114 |
+
robotics = "robotics"
|
115 |
+
maintenance_management = "maintenance management"
|
116 |
+
|
117 |
+
# Define the schema for the output.
|
118 |
+
class Metadata(BaseModel):
|
119 |
+
title: str = Field(description='Title of the document')
|
120 |
+
summary: str = Field(description='One sentence short summary of the document information')
|
121 |
+
disciplines: List[str] = Field(
|
122 |
+
default_factory=list,
|
123 |
+
description='BIM disciplines the document belongs to',
|
124 |
+
example=['S - Sanitär', 'D - Datennetz']
|
125 |
+
)
|
126 |
+
keywords: List[str] = Field(
|
127 |
+
default_factory=list,
|
128 |
+
description='List of BIM keywords associated with the document',
|
129 |
+
example=['3D Modelling', 'Clash detection']
|
130 |
+
)
|
together_call.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
import openai
|
4 |
+
from pydantic import BaseModel, Field
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
load_dotenv()
|
7 |
+
|
8 |
+
|
9 |
+
# Create client
|
10 |
+
client = openai.OpenAI(
|
11 |
+
base_url="https://api.together.xyz/v1",
|
12 |
+
api_key=os.environ["TOGETHER_API_KEY"],
|
13 |
+
)
|
14 |
+
|
15 |
+
# Define the schema for the output.
|
16 |
+
class User(BaseModel):
|
17 |
+
name: str = Field(description="user name")
|
18 |
+
address: str = Field(description="address")
|
19 |
+
|
20 |
+
# Call the LLM with the JSON schema
|
21 |
+
chat_completion = client.chat.completions.create(
|
22 |
+
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
|
23 |
+
response_format={"type": "json_object", "schema": User.model_json_schema()},
|
24 |
+
messages=[
|
25 |
+
{
|
26 |
+
"role": "system",
|
27 |
+
"content": "You are a helpful assistant that answers in JSON.",
|
28 |
+
},
|
29 |
+
{
|
30 |
+
"role": "user",
|
31 |
+
"content": "Create a user named Alice, who lives in 42, Wonderland Avenue.",
|
32 |
+
},
|
33 |
+
],
|
34 |
+
)
|
35 |
+
|
36 |
+
created_user = json.loads(chat_completion.choices[0].message.content)
|
37 |
+
print(json.dumps(created_user, indent=2))
|
38 |
+
|
39 |
+
"""
|
40 |
+
{
|
41 |
+
"address": "42, Wonderland Avenue",
|
42 |
+
"name": "Alice"
|
43 |
+
}
|
44 |
+
"""
|