Route birth runner through OpenAI runtime
This commit is contained in:
parent
8516da46ff
commit
1813915b00
8 changed files with 209 additions and 20 deletions
|
|
@ -245,6 +245,28 @@ pub fn store_openai_request(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn assistant_text_from_openai_events(
|
||||
store_path: impl AsRef<Path>,
|
||||
request_id: &str,
|
||||
) -> Result<String> {
|
||||
let mut cache = runtime_spine_cache(store_path)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
let mut events = cache
|
||||
.get_all::<EpiphanyOpenAiStreamEvent>()?
|
||||
.into_iter()
|
||||
.filter(|event| event.request_id == request_id)
|
||||
.collect::<Vec<_>>();
|
||||
events.sort_by_key(|event| event.sequence);
|
||||
|
||||
let mut text = String::new();
|
||||
for event in events {
|
||||
if let EpiphanyOpenAiStreamPayload::TextDelta { text: delta } = event.payload {
|
||||
text.push_str(&delta);
|
||||
}
|
||||
}
|
||||
Ok(text)
|
||||
}
|
||||
|
||||
pub fn default_codex_home() -> Result<PathBuf> {
|
||||
if let Ok(path) = std::env::var("CODEX_HOME") {
|
||||
return Ok(PathBuf::from(path));
|
||||
|
|
@ -387,6 +409,7 @@ mod tests {
|
|||
let summary = record_openai_events(&store, &options, &request, &events)?;
|
||||
|
||||
assert_eq!(summary.verdict, "pass");
|
||||
assert_eq!(assistant_text_from_openai_events(&store, "req-1")?, "");
|
||||
let mut cache = runtime_spine_cache(&store)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
assert!(cache.get::<EpiphanyOpenAiModelRequest>("req-1")?.is_some());
|
||||
|
|
|
|||
Reference in a new issue