Skip to content

Commit 0c60abc

Browse files
authored
Revert "Jiayu-fix bugs in LLM (#109)"
This reverts commit 1bcc8d0.
1 parent 1bcc8d0 commit 0c60abc

File tree

5 files changed

+73
-27
lines changed

5 files changed

+73
-27
lines changed

Stanford360/Protein/Model/PromptTemplate.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ class ProteinPromptConstructor: ObservableObject {
1515
func constructPrompt(mealName: String) -> String {
1616
let prompt = """
1717
You are an expert in nutritional science with a focus on dietary needs for children aged 10-15.
18-
Here are some important information that you can refer:
19-
1. Those belong to Meats, Poultry, and Fish usually around 6-10 grams.
20-
2. Those belong to Soy and Vegetable Protein usually around 3-13 grams.
21-
3. Those belong to Legumes and Nuts usually around 5-10 grams.
22-
4. Those belong to Milk and Dairy usually around 10 grams.
23-
5. Those belong to Vegetables usually around 2 grams.
24-
6. Those belong to Grains usually around 5-10 grams.
18+
2519
Task:
2620
1. Analyze the meal name: "\(mealName)"
2721
2. Determine the appropriate protein content (in grams) based on nutritional standards for this age group.

Stanford360/Protein/View/AddMealView.swift

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -350,23 +350,24 @@ extension AddMealView {
350350
self.proteinAmount = ""
351351
}
352352
let prompt = promptTemplate.constructPrompt(mealName: meal)
353-
354-
let llmSchema = LLMLocalSchema(
355-
// model: .custom(id: <#T##String#>),
356-
model: .llama3_2_1B_4bit,
357-
parameters: .init(
358-
systemPrompt: prompt
353+
let llmSession: LLMLocalSession = runner(
354+
with: LLMLocalSchema(
355+
model: .llama3_8B_4bit,
356+
parameters: .init(
357+
systemPrompt: prompt
358+
)
359359
)
360360
)
361-
let llmSession = runner(with: llmSchema)
362-
var output = ""
363-
361+
// let llmSession: LLMLocalSession = runner(
362+
// with: LLMLocalSchema(
363+
// model: .llama3_8B_4bit
364+
// )
365+
// )
364366
do {
365367
for try await token in try await llmSession.generate() {
366-
output.append(token)
367-
}
368-
await MainActor.run {
369-
self.proteinAmount = output
368+
await MainActor.run {
369+
self.proteinAmount.append(token)
370+
}
370371
}
371372
print("Protein extracted is ", proteinAmount)
372373
} catch {

Stanford360/Protein/View/LLMLocalOnboardingDownloadView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ struct LLMLocalOnboardingDownloadView: View {
2323

2424
var body: some View {
2525
LLMLocalDownloadView(
26-
model: .llama3_2_1B_4bit,
27-
downloadDescription: "The Llama3 1B model will be downloaded"
26+
model: .llama3_8B_4bit,
27+
downloadDescription: "The Llama3 8B model will be downloaded"
2828
) {
2929
onboardingNavigationPath.nextStep()
3030
}

Stanford360/Resources/Localizable.xcstrings

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,6 @@
332332

333333
},
334334
"Hydration Recommendations" : {
335-
336-
},
337-
"image" : {
338-
339335
},
340336
"image" : {
341337

@@ -707,7 +703,7 @@
707703
"Task completed for day %lld" : {
708704

709705
},
710-
"The Llama3 1B model will be downloaded" : {
706+
"The Llama3 8B model will be downloaded" : {
711707

712708
},
713709
"The Spezi Framework" : {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// ProteinPromptConstructorTest.swift
3+
// Stanford360
4+
//
5+
// Created by jiayu chang on 3/11/25.
6+
//
7+
// This source file is part of the Stanford 360 based on the Stanford Spezi Template Application project
8+
//
9+
// SPDX-FileCopyrightText: 2025 Stanford University
10+
//
11+
// SPDX-License-Identifier: MIT
12+
//
13+
14+
@testable import Stanford360
15+
import XCTest
16+
17+
final class ProteinPromptConstructorTests: XCTestCase {
18+
var promptConstructor = ProteinPromptConstructor()
19+
20+
// Test if constructPrompt() generates the correct format
21+
func testConstructPrompt() {
22+
let mealName = "Grilled Chicken"
23+
let expectedPrompt = """
24+
You are an expert in nutritional science with a focus on dietary needs for children aged 10-15.
25+
26+
Task:
27+
1. Analyze the meal name: "\(mealName)"
28+
2. Determine the appropriate protein content (in grams) based on nutritional standards for this age group.
29+
3. Respond with a single numeric value representing the protein content in grams.
30+
4. Do not include any additional text in your response.
31+
"""
32+
33+
let result = promptConstructor.constructPrompt(mealName: mealName)
34+
35+
XCTAssertEqual(result, expectedPrompt, "Prompt output does not match expected format.")
36+
}
37+
38+
// Test if constructPrompt() handles an empty meal name correctly
39+
func testConstructPromptWithEmptyMealName() {
40+
let mealName = ""
41+
let expectedPrompt = """
42+
You are an expert in nutritional science with a focus on dietary needs for children aged 10-15.
43+
44+
Task:
45+
1. Analyze the meal name: "\(mealName)"
46+
2. Determine the appropriate protein content (in grams) based on nutritional standards for this age group.
47+
3. Respond with a single numeric value representing the protein content in grams.
48+
4. Do not include any additional text in your response.
49+
"""
50+
51+
let result = promptConstructor.constructPrompt(mealName: mealName)
52+
53+
XCTAssertEqual(result, expectedPrompt, "Prompt should handle an empty meal name correctly.")
54+
}
55+
}

0 commit comments

Comments
 (0)