File tree Expand file tree Collapse file tree 5 files changed +62
-3
lines changed Expand file tree Collapse file tree 5 files changed +62
-3
lines changed Original file line number Diff line number Diff line change 79
79
default = "objective"
80
80
)
81
81
82
+ # =====================================
83
+ # Arg: Encoding
84
+ # =====================================
85
+
86
+ cli .add_argument (
87
+ "--encoding" ,
88
+ type = str ,
89
+ help = "The encoding to use for the output file (default: utf-8)." ,
90
+ default = "utf-8"
91
+ )
92
+
82
93
# =====================================
83
94
# Arg: Query Domains
84
95
# =====================================
@@ -134,7 +145,8 @@ async def main(args):
134
145
query = args .query ,
135
146
query_domains = query_domains ,
136
147
report_type = args .report_type ,
137
- tone = tone_map [args .tone ]
148
+ tone = tone_map [args .tone ],
149
+ encoding = args .encoding
138
150
)
139
151
140
152
await researcher .conduct_research ()
@@ -144,7 +156,7 @@ async def main(args):
144
156
# Write the report to a file
145
157
artifact_filepath = f"outputs/{ uuid4 ()} .md"
146
158
os .makedirs ("outputs" , exist_ok = True )
147
- with open (artifact_filepath , "w" ) as f :
159
+ with open (artifact_filepath , "w" , encoding = "utf-8" ) as f :
148
160
f .write (report )
149
161
150
162
print (f"Report written to '{ artifact_filepath } '" )
Original file line number Diff line number Diff line change
1
+ Subproject commit cd64f77268012397f245ef19670eccc997a7f581
Original file line number Diff line number Diff line change @@ -154,6 +154,9 @@ def __init__(
154
154
self .memory = Memory (
155
155
self .cfg .embedding_provider , self .cfg .embedding_model , ** self .cfg .embedding_kwargs
156
156
)
157
+
158
+ # Set default encoding to utf-8
159
+ self .encoding = kwargs .get ('encoding' , 'utf-8' )
157
160
158
161
# Initialize components
159
162
self .research_conductor : ResearchConductor = ResearchConductor (self )
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ def scrape(self) -> tuple:
61
61
62
62
# Extract the content (markdown) and title from FireCrawl response
63
63
content = response .data .markdown
64
- title = response [ " metadata" ][ " title"]
64
+ title = response . metadata . get ( " title", "" )
65
65
66
66
# Parse the HTML content of the response to create a BeautifulSoup object for the utility functions
67
67
response_bs = self .session .get (self .link , timeout = 4 )
Original file line number Diff line number Diff line change
1
+ import json
2
+ from typing import Dict , Any
3
+ from pydantic import BaseModel
4
+
5
+ class UserSchema (BaseModel ):
6
+ id : int
7
+ name : str
8
+ email : str
9
+ age : int
10
+ is_active : bool
11
+
12
+ def generate_structured_json (schema : BaseModel , data : Dict [str , Any ]) -> str :
13
+ """
14
+ Generate structured JSON output based on provided schema
15
+
16
+ Args:
17
+ schema: Pydantic model defining the schema structure
18
+ data: Dictionary containing the data to be structured
19
+
20
+ Returns:
21
+ str: JSON string with structured data
22
+ """
23
+ try :
24
+ # Create instance of schema with provided data
25
+ structured_data = schema (** data )
26
+ # Convert to JSON string
27
+ return json .dumps (structured_data .dict (), indent = 2 )
28
+ except Exception as e :
29
+ return f"Error generating JSON: { str (e )} "
30
+
31
+ # Example usage
32
+ if __name__ == "__main__" :
33
+ sample_data = {
34
+ "id" : 1 ,
35
+ "name" : "John Doe" ,
36
+
37
+ "age" : 30 ,
38
+ "is_active" : True
39
+ }
40
+
41
+ json_output = generate_structured_json (UserSchema , sample_data )
42
+ print ("Structured JSON Output:" )
43
+ print (json_output )
You can’t perform that action at this time.
0 commit comments