Skip to content

Commit f75aca4

Browse files
authored
Fix invalid construction of greedy sampler in LlamaLanguageModel (#55)
* Fix invalid construction of greedy sampler in LlamaLanguageModel * Construct model once in LlamaLanguageModelTests
1 parent 6b7600d commit f75aca4

2 files changed

Lines changed: 6 additions & 20 deletions

File tree

Sources/AnyLanguageModel/Models/LlamaLanguageModel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ import Foundation
431431
case .greedy:
432432
llama_sampler_chain_add(sampler, llama_sampler_init_top_k(1))
433433
llama_sampler_chain_add(sampler, llama_sampler_init_top_p(1.0, 1))
434+
llama_sampler_chain_add(sampler, llama_sampler_init_greedy())
434435
case .topK(let k, let seed):
435436
llama_sampler_chain_add(sampler, llama_sampler_init_top_k(Int32(k)))
436437
llama_sampler_chain_add(sampler, llama_sampler_init_top_p(1.0, 1))

Tests/AnyLanguageModelTests/LlamaLanguageModelTests.swift

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@ import Testing
1010
.enabled(if: ProcessInfo.processInfo.environment["LLAMA_MODEL_PATH"] != nil)
1111
)
1212
struct LlamaLanguageModelTests {
13-
let modelPath: String = ProcessInfo.processInfo.environment["LLAMA_MODEL_PATH"] ?? ""
14-
15-
var model: LlamaLanguageModel {
16-
LlamaLanguageModel(
17-
modelPath: modelPath,
18-
contextSize: 2048,
19-
temperature: 0.8
20-
)
21-
}
13+
let model = LlamaLanguageModel(
14+
modelPath: ProcessInfo.processInfo.environment["LLAMA_MODEL_PATH"]!,
15+
contextSize: 2048,
16+
temperature: 0.8
17+
)
2218

2319
@Test func initialization() {
2420
let customModel = LlamaLanguageModel(
@@ -102,17 +98,6 @@ import Testing
10298
#expect(!secondResponse.content.isEmpty)
10399
}
104100

105-
@Test func customTemperature() async throws {
106-
let highTempModel = LlamaLanguageModel(
107-
modelPath: modelPath,
108-
temperature: 1.5
109-
)
110-
111-
let session = LanguageModelSession(model: highTempModel)
112-
let response = try await session.respond(to: "Say something creative")
113-
#expect(!response.content.isEmpty)
114-
}
115-
116101
@Test func maxTokensLimit() async throws {
117102
let session = LanguageModelSession(model: model)
118103

0 commit comments

Comments
 (0)