File tree Expand file tree Collapse file tree 12 files changed +154
-178
lines changed Expand file tree Collapse file tree 12 files changed +154
-178
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ Ensure your `settings.json` has:
13
13
1 . Run ` poetry install `
14
14
2 . Run ` poetry shell `
15
15
3 . Open up vscode command palette (command + shift + p, and select the .venv folder that was created in this directory as the interpreter)
16
- 4 . Run ` uvicorn fastapi_starter .app:app --reload `
16
+ 4 . Run ` uvicorn fast_api_starter .app:app --reload `
17
17
5 . Curl the streaming endpoint:
18
18
```
19
19
curl -X GET -H "Content-Type: application/json" http://localhost:8000/extract_resume
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -10,23 +10,18 @@ class Education {
10
10
year int
11
11
}
12
12
13
- function ExtractResume {
14
- input string
15
- output Resume
16
- }
17
-
18
- impl<llm, ExtractResume> version1 {
13
+ function ExtractResume(raw_text: string) -> Resume {
19
14
client GPT4
20
15
prompt #"
21
16
Parse the following resume and return a structured representation of the data in the schema below.
22
17
23
18
Resume:
24
19
---
25
- {#input }
20
+ {{raw_text} }
26
21
---
27
22
28
23
Output JSON format (only include these fields, and no others):
29
- {#print_type(output) }
24
+ {{ ctx.output_format(prefix=null) } }
30
25
31
26
Output JSON:
32
27
"#
Original file line number Diff line number Diff line change @@ -6,23 +6,42 @@ enum Category {
6
6
Question
7
7
}
8
8
9
- function ClassifyMessage {
10
- input (message: string, message_date: string)
11
- output Category[]
9
+ class Message {
10
+ role Role
11
+ content string
12
12
}
13
13
14
- impl<llm, ClassifyMessage> level1 {
14
+ enum Role {
15
+ Customer
16
+ Assistant
17
+ }
18
+
19
+ template_string PrintMessage(msg: Message, prefix: string?) #"
20
+ {{ _.chat('user' if msg.role == "Customer" else 'assistant') }}
21
+ {% if prefix %}
22
+ {{ prefix }}
23
+ {% endif %}
24
+ {{ msg.content }}
25
+ "#
26
+
27
+ function ClassifyMessage(convo: Message[]) -> Category[] {
15
28
client GPT4
16
29
prompt #"
17
- Classify the following INPUT into following:
18
- {#print_enum(Category)}
30
+ {#
31
+ Prompts are auto-dedented and trimmed.
32
+ We use JINJA for our prompt syntax
33
+ (but we added some static analysis to make sure it's valid!)
34
+ #}
35
+
36
+ {{ ctx.output_format(prefix="Classify with the following json:") }}
19
37
20
- INPUT
21
- ---
22
- date: {#input.message_date}
23
- message: {#input.message }
24
- ---
38
+ {% for c in convo %}
39
+ {{ PrintMessage(c,
40
+ 'This is the message to classify:' if loop.last and convo|length > 1 else null
41
+ ) } }
42
+ {% endfor %}
25
43
44
+ {{ _.chat('assistant') }}
26
45
JSON array of categories that match:
27
46
"#
28
47
}
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ async def extract_resume():
43
43
- Wrote code in Python and Java
44
44
"""
45
45
async def stream_resume (resume ):
46
- async with b .ExtractResume .stream (resume ) as stream :
46
+ async with b .ExtractResume .stream (raw_text = resume ) as stream :
47
47
async for chunk in stream .parsed_stream :
48
48
print (chunk .delta )
49
49
if chunk .is_parseable :
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ packages = [
13
13
python = " ^3.11"
14
14
fastapi = " ^0.110.0"
15
15
uvicorn = {extras = [" standard" ], version = " ^0.29.0" }
16
- baml = " 0.17.1 "
16
+ baml = " ^0.19.0 "
17
17
18
18
19
19
[build-system ]
Original file line number Diff line number Diff line change 1
1
export const dynamic = 'force-dynamic'
2
2
3
3
import b from '../../../baml_client'
4
+ import { Role } from '../../../baml_client/types' ;
4
5
5
6
export async function POST ( request : Request ) {
6
7
const result = await b . ClassifyMessage ( {
7
- message : "I would like to cancel my order!" ,
8
- message_date : "2021-01-01T00:00:00Z" ,
8
+ convo : [
9
+ {
10
+ role : Role . Customer ,
11
+ content : "I want to cancel my subscription"
12
+ }
13
+ ]
9
14
} ) ;
10
15
11
16
return Response . json ( result ) ;
Original file line number Diff line number Diff line change @@ -10,23 +10,18 @@ class Education {
10
10
year int
11
11
}
12
12
13
- function ExtractResume {
14
- input string
15
- output Resume
16
- }
17
-
18
- impl<llm, ExtractResume> version1 {
13
+ function ExtractResume(raw_text: string) -> Resume {
19
14
client GPT4
20
15
prompt #"
21
16
Parse the following resume and return a structured representation of the data in the schema below.
22
17
23
18
Resume:
24
19
---
25
- {#input }
20
+ {{raw_text} }
26
21
---
27
22
28
23
Output JSON format (only include these fields, and no others):
29
- {#print_type(output) }
24
+ {{ ctx.output_format(prefix=null) } }
30
25
31
26
Output JSON:
32
27
"#
Original file line number Diff line number Diff line change @@ -6,23 +6,42 @@ enum Category {
6
6
Question
7
7
}
8
8
9
- function ClassifyMessage {
10
- input (message: string, message_date: string)
11
- output Category[]
9
+ class Message {
10
+ role Role
11
+ content string
12
12
}
13
13
14
- impl<llm, ClassifyMessage> level1 {
14
+ enum Role {
15
+ Customer
16
+ Assistant
17
+ }
18
+
19
+ template_string PrintMessage(msg: Message, prefix: string?) #"
20
+ {{ _.chat('user' if msg.role == "Customer" else 'assistant') }}
21
+ {% if prefix %}
22
+ {{ prefix }}
23
+ {% endif %}
24
+ {{ msg.content }}
25
+ "#
26
+
27
+ function ClassifyMessage(convo: Message[]) -> Category[] {
15
28
client GPT4
16
29
prompt #"
17
- Classify the following INPUT into following:
18
- {#print_enum(Category)}
30
+ {#
31
+ Prompts are auto-dedented and trimmed.
32
+ We use JINJA for our prompt syntax
33
+ (but we added some static analysis to make sure it's valid!)
34
+ #}
35
+
36
+ {{ ctx.output_format(prefix="Classify with the following json:") }}
19
37
20
- INPUT
21
- ---
22
- date: {#input.message_date}
23
- message: {#input.message }
24
- ---
38
+ {% for c in convo %}
39
+ {{ PrintMessage(c,
40
+ 'This is the message to classify:' if loop.last and convo|length > 1 else null
41
+ ) } }
42
+ {% endfor %}
25
43
44
+ {{ _.chat('assistant') }}
26
45
JSON array of categories that match:
27
46
"#
28
47
}
You can’t perform that action at this time.
0 commit comments