Merge branch 'worktree-agent-a52dc99d769b245fb'
This commit is contained in:
Vendored
+400
@@ -0,0 +1,400 @@
|
||||
#pragma once
|
||||
|
||||
// FIXTURES taken verbatim from the x-fern-examples of cohere-openapi.yaml
|
||||
// (cohere-ai/cohere-developer-experience, read 2026-10-25), JSON re-serialized.
|
||||
// Generated once from the document; edit nothing by hand. Nothing here is a
|
||||
// recorded live reply: the spec examples are the only vendor output we have.
|
||||
|
||||
namespace cohere_test {
|
||||
|
||||
// FIXTURE: v2/chat example 0 response
|
||||
inline const char* kChatBasic =
|
||||
R"COHERE({"id": "c14c80c3-18eb-4519-9460-6c92edd8cfb4", "message": {"role": "assistant", "content": [{"type": "text", "text": "LLMs stand for Large Language Models, which are a type of neural network model specialized in processing and generating human language. They are designed to understand and respond to natural language input and have become increasingly popular and valuable in recent years.\n\nLLMs are trained on vast amounts of text data, enabling them to learn patterns, grammar, and semantic meanings present in the language. These models can then be used for various natural language processing tasks, such as text generation, summarization, question answering, machine translation, sentiment analysis, and even some aspects of natural language understanding.\n\nSome well-known examples of LLMs include:\n\n1. GPT-3 (Generative Pre-trained Transformer 3) \u2014 An open-source LLM developed by OpenAI, capable of generating human-like text and performing various language tasks.\n\n2. BERT (Bidirectional Encoder Representations from Transformers) \u2014 A Google-developed LLM that is particularly good at understanding contextual relationships in text, and is widely used for natural language understanding tasks like sentiment analysis and named entity recognition.\n\n3. T5 (Text-to-Text Transfer Transformer) \u2014 Also from Google, T5 is a flexible LLM that frames all language tasks as text-to-text problems, where the model learns to generate output text based on input text prompts.\n\n4. RoBERTa (Robustly Optimized BERT Approach) \u2014 A variant of BERT that uses additional training techniques to improve performance.\n\n5. DeBERTa (Decoding-enhanced BERT with disentangled attention) \u2014 Another variant of BERT that introduces a new attention mechanism.\n\nLLMs have become increasingly powerful and larger in scale, improving the accuracy and sophistication of language tasks. They are also being used as a foundation for developing various applications, including chatbots,)COHERE"
|
||||
R"COHERE( content recommendation systems, language translation services, and more.\nThe future of LLMs holds the potential for even more sophisticated language technologies, with ongoing research and development focused on enhancing their capabilities, improving efficiency, and exploring their applications in various domains."}]}, "finish_reason": "COMPLETE", "usage": {"billed_units": {"input_tokens": 5, "output_tokens": 418}, "tokens": {"input_tokens": 71, "output_tokens": 418}}})COHERE"
|
||||
;
|
||||
|
||||
// FIXTURE: v2/chat example 1 response
|
||||
inline const char* kChatCitations =
|
||||
R"COHERE({"id": "c14c80c3-18eb-4519-9460-6c92edd8cfb4", "message": {"role": "assistant", "content": [{"type": "text", "text": "Both NSync and Backstreet Boys were extremely popular at the turn of the millennium. Backstreet Boys had massive album sales across the globe, great singles sales, plenty of chart-topping releases, hyped tours, and tremendous media coverage. NSync also had huge sales, with their album No Strings Attached selling 2.4 million units in its first week. They also had the second fastest-selling album of the Soundscan era before 2015, with Celebrity debuting at 1.88 million units sold.\n\nWhile it is difficult to say for sure which of the two bands was more popular, Backstreet Boys did have success in some countries that were traditionally hard to penetrate for Western artists."}], "citations": [{"start": 36, "end": 84, "text": "extremely popular at the turn of the millennium.", "sources": [{"type": "document", "id": "doc:1", "document": {"snippet": "\u2193 Skip to Main Content\n\nMusic industry \u2013 One step closer to being accurate\n\nCSPC: NSYNC Popularity Analysis\n\nMJD Posted on February 9, 2018 Posted in CSPC 27 Comments Tagged with Boy band, N'Sync\n\nAt the turn of the millennium three teen acts were huge in the US, the Backstreet Boys, Britney Spears and NSYNC. The latter is the only one we haven\u2019t study so far. It took 15 years and Adele to break their record of 2,4 million units sold of No Strings Attached in its first week alone.\n\nIt wasn\u2019t a fluke, as the second fastest selling album of the Soundscan era prior 2015, was also theirs since Celebrity debuted with 1,88 million units sold.", "title": "CSPC: NSYNC Popularity Analysis - ChartMasters"}}]}, {"start": 105, "end": 141, "text": "massive album sales across the globe", "sources": [{"type": "document", "id": "doc:0", "document": {"snippet": "\u2193 Skip to Main Content\n\nMusic industry \u2013 One step closer to being accurate\n\nCSPC: Backstreet Boys Popularity Analysis\n\nHer)COHERE"
|
||||
R"COHERE(n\u00e1n Lopez Posted on February 9, 2017 Posted in CSPC 72 Comments Tagged with Backstreet Boys, Boy band\n\nAt one point, Backstreet Boys defined success: massive albums sales across the globe, great singles sales, plenty of chart topping releases, hugely hyped tours and tremendous media coverage.\n\nIt is true that they benefited from extraordinarily good market conditions in all markets. After all, the all-time record year for the music business, as far as revenues in billion dollars are concerned, was actually 1999. That is, back when this five men group was at its peak.", "title": "CSPC: Backstreet Boys Popularity Analysis - ChartMasters"}}]}, {"start": 143, "end": 162, "text": "great singles sales", "sources": [{"type": "document", "id": "doc:0", "document": {"snippet": "\u2193 Skip to Main Content\n\nMusic industry \u2013 One step closer to being accurate\n\nCSPC: Backstreet Boys Popularity Analysis\n\nHern\u00e1n Lopez Posted on February 9, 2017 Posted in CSPC 72 Comments Tagged with Backstreet Boys, Boy band\n\nAt one point, Backstreet Boys defined success: massive albums sales across the globe, great singles sales, plenty of chart topping releases, hugely hyped tours and tremendous media coverage.\n\nIt is true that they benefited from extraordinarily good market conditions in all markets. After all, the all-time record year for the music business, as far as revenues in billion dollars are concerned, was actually 1999. That is, back when this five men group was at its peak.", "title": "CSPC: Backstreet Boys Popularity Analysis - ChartMasters"}}]}, {"start": 164, "end": 196, "text": "plenty of chart-topping releases", "sources": [{"type": "document", "id": "doc:0", "document": {"snippet": "\u2193 Skip to Main Content\n\nMusic industry \u2013 One step closer to being accurate\n\nCSPC: Backstreet Boys Popularity Analysis\n\nHern\u00e1n Lopez Posted on February 9, 2017 Posted in CSPC 72 Comments Tagged with Backstreet Boys, Boy band\n\nAt one point, Backstree)COHERE"
|
||||
R"COHERE(t Boys defined success: massive albums sales across the globe, great singles sales, plenty of chart topping releases, hugely hyped tours and tremendous media coverage.\n\nIt is true that they benefited from extraordinarily good market conditions in all markets. After all, the all-time record year for the music business, as far as revenues in billion dollars are concerned, was actually 1999. That is, back when this five men group was at its peak.", "title": "CSPC: Backstreet Boys Popularity Analysis - ChartMasters"}}]}, {"start": 198, "end": 209, "text": "hyped tours", "sources": [{"type": "document", "id": "doc:0", "document": {"snippet": "\u2193 Skip to Main Content\n\nMusic industry \u2013 One step closer to being accurate\n\nCSPC: Backstreet Boys Popularity Analysis\n\nHern\u00e1n Lopez Posted on February 9, 2017 Posted in CSPC 72 Comments Tagged with Backstreet Boys, Boy band\n\nAt one point, Backstreet Boys defined success: massive albums sales across the globe, great singles sales, plenty of chart topping releases, hugely hyped tours and tremendous media coverage.\n\nIt is true that they benefited from extraordinarily good market conditions in all markets. After all, the all-time record year for the music business, as far as revenues in billion dollars are concerned, was actually 1999. That is, back when this five men group was at its peak.", "title": "CSPC: Backstreet Boys Popularity Analysis - ChartMasters"}}]}, {"start": 215, "end": 241, "text": "tremendous media coverage.", "sources": [{"type": "document", "id": "doc:0", "document": {"snippet": "\u2193 Skip to Main Content\n\nMusic industry \u2013 One step closer to being accurate\n\nCSPC: Backstreet Boys Popularity Analysis\n\nHern\u00e1n Lopez Posted on February 9, 2017 Posted in CSPC 72 Comments Tagged with Backstreet Boys, Boy band\n\nAt one point, Backstreet Boys defined success: massive albums sales across the globe, great singles sales, plenty of chart topping releases, hugely hyped tours and tremen)COHERE"
|
||||
R"COHERE(dous media coverage.\n\nIt is true that they benefited from extraordinarily good market conditions in all markets. After all, the all-time record year for the music business, as far as revenues in billion dollars are concerned, was actually 1999. That is, back when this five men group was at its peak.", "title": "CSPC: Backstreet Boys Popularity Analysis - ChartMasters"}}]}, {"start": 280, "end": 350, "text": "album No Strings Attached selling 2.4 million units in its first week.", "sources": [{"type": "document", "id": "doc:1", "document": {"snippet": "\u2193 Skip to Main Content\n\nMusic industry \u2013 One step closer to being accurate\n\nCSPC: NSYNC Popularity Analysis\n\nMJD Posted on February 9, 2018 Posted in CSPC 27 Comments Tagged with Boy band, N'Sync\n\nAt the turn of the millennium three teen acts were huge in the US, the Backstreet Boys, Britney Spears and NSYNC. The latter is the only one we haven\u2019t study so far. It took 15 years and Adele to break their record of 2,4 million units sold of No Strings Attached in its first week alone.\n\nIt wasn\u2019t a fluke, as the second fastest selling album of the Soundscan era prior 2015, was also theirs since Celebrity debuted with 1,88 million units sold.", "title": "CSPC: NSYNC Popularity Analysis - ChartMasters"}}]}, {"start": 369, "end": 430, "text": "second fastest-selling album of the Soundscan era before 2015", "sources": [{"type": "document", "id": "doc:1", "document": {"snippet": "\u2193 Skip to Main Content\n\nMusic industry \u2013 One step closer to being accurate\n\nCSPC: NSYNC Popularity Analysis\n\nMJD Posted on February 9, 2018 Posted in CSPC 27 Comments Tagged with Boy band, N'Sync\n\nAt the turn of the millennium three teen acts were huge in the US, the Backstreet Boys, Britney Spears and NSYNC. The latter is the only one we haven\u2019t study so far. It took 15 years and Adele to break their record of 2,4 million units sold of No Strings Attached in its first week alone.\n\nIt wasn\u2019t )COHERE"
|
||||
R"COHERE(a fluke, as the second fastest selling album of the Soundscan era prior 2015, was also theirs since Celebrity debuted with 1,88 million units sold.", "title": "CSPC: NSYNC Popularity Analysis - ChartMasters"}}]}, {"start": 437, "end": 483, "text": "Celebrity debuting at 1.88 million units sold.", "sources": [{"type": "document", "id": "doc:1", "document": {"snippet": "\u2193 Skip to Main Content\n\nMusic industry \u2013 One step closer to being accurate\n\nCSPC: NSYNC Popularity Analysis\n\nMJD Posted on February 9, 2018 Posted in CSPC 27 Comments Tagged with Boy band, N'Sync\n\nAt the turn of the millennium three teen acts were huge in the US, the Backstreet Boys, Britney Spears and NSYNC. The latter is the only one we haven\u2019t study so far. It took 15 years and Adele to break their record of 2,4 million units sold of No Strings Attached in its first week alone.\n\nIt wasn\u2019t a fluke, as the second fastest selling album of the Soundscan era prior 2015, was also theirs since Celebrity debuted with 1,88 million units sold.", "title": "CSPC: NSYNC Popularity Analysis - ChartMasters"}}]}, {"start": 589, "end": 677, "text": "success in some countries that were traditionally hard to penetrate for Western artists.", "sources": [{"type": "document", "id": "doc:2", "document": {"snippet": "1997, 1998, 2000 and 2001 also rank amongst some of the very best years.\nYet the way many music consumers \u2013 especially teenagers and young women\u2019s \u2013 embraced their output deserves its own chapter. If Jonas Brothers and more recently One Direction reached a great level of popularity during the past decade, the type of success achieved by Backstreet Boys is in a completely different level as they really dominated the business for a few years all over the world, including in some countries that were traditionally hard to penetrate for Western artists.\n\nWe will try to analyze the extent of that hegemony with this new article with final results which will more than su)COHERE"
|
||||
R"COHERE(rprise many readers.", "title": "CSPC: Backstreet Boys Popularity Analysis - ChartMasters"}}]}]}, "finish_reason": "COMPLETE", "usage": {"billed_units": {"input_tokens": 682, "output_tokens": 143}, "tokens": {"input_tokens": 1380, "output_tokens": 434}}})COHERE"
|
||||
;
|
||||
|
||||
// FIXTURE: v2/chat example 3 response
|
||||
inline const char* kChatToolThinking =
|
||||
R"COHERE({"id": "9e5f00aa-bf1e-481a-abe3-0eceac18c3ec", "message": {"role": "assistant", "content": [{"type": "thinking", "thinking": "I will first find the sales summary for 29th September 2023. Then, I will find the details of the products in the 'Electronics' category."}], "tool_calls": [{"id": "query_daily_sales_report_hgxxmkby3wta", "type": "function", "function": {"name": "query_daily_sales_report", "arguments": "{\"day\": \"2023-09-29\"}"}}, {"id": "query_product_catalog_rpg0z5h8yyz2", "type": "function", "function": {"name": "query_product_catalog", "arguments": "{\"category\": \"Electronics\"}"}}]}, "finish_reason": "TOOL_CALL", "usage": {"billed_units": {"input_tokens": 127, "output_tokens": 69}, "tokens": {"input_tokens": 1032, "output_tokens": 124}}})COHERE"
|
||||
;
|
||||
|
||||
// FIXTURE: v2/chat example 2 stream
|
||||
inline const char* kStreamText =
|
||||
R"COHERE(event: message-start
|
||||
data: {"type": "message-start", "id": "29f14a5a-11de-4cae-9800-25e4747408ea", "delta": {"message": {"role": "assistant"}}}
|
||||
|
||||
event: content-start
|
||||
data: {"type": "content-start", "index": 0, "delta": {"message": {"content": {"type": "text", "text": ""}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": "LL"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": "Ms"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " stand"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " for"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " Large"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " Language"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " Models"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": ","}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " which"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " are"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " a"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " type"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " of"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " neural"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta)COHERE"
|
||||
R"COHERE(", "index": 0, "delta": {"message": {"content": {"text": " network"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " model"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " specialized"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " in"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " processing"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " and"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " generating"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " human"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": " language"}}}}
|
||||
|
||||
event: content-delta
|
||||
data: {"type": "content-delta", "index": 0, "delta": {"message": {"content": {"text": "."}}}}
|
||||
|
||||
event: content-end
|
||||
data: {"type": "content-end", "index": 0}
|
||||
|
||||
event: message-end
|
||||
data: {"type": "message-end", "delta": {"finish_reason": "COMPLETE", "usage": {"billed_units": {"input_tokens": 5, "output_tokens": 26}, "tokens": {"input_tokens": 71, "output_tokens": 26}}}}
|
||||
|
||||
)COHERE"
|
||||
;
|
||||
|
||||
// FIXTURE: v2/chat example 6 stream
|
||||
inline const char* kStreamTools =
|
||||
R"COHERE(event: message-start
|
||||
data: {"type": "message-start", "id": "2edfdf70-019c-4f7a-be20-3cdbfaa3dca6", "delta": {"message": {"role": "assistant"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "I"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " will"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " use"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " the"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " query"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "_"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "daily"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "_"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "sales"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "_"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "report"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " tool"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " to"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " find"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " the"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " sales"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " summary"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " for"}}}
|
||||
)COHERE"
|
||||
R"COHERE(
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " 2"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "9"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "th"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " September"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " 2"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "0"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "2"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "3"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "."}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " I"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " will"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " also"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " use"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " the"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " query"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "_"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "product"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "_"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "catalog"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta")COHERE"
|
||||
R"COHERE(, "delta": {"message": {"tool_plan": " tool"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " to"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " find"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " the"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " details"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " of"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " the"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " products"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " in"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " the"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " Electronics"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": " category"}}}
|
||||
|
||||
event: tool-plan-delta
|
||||
data: {"type": "tool-plan-delta", "delta": {"message": {"tool_plan": "."}}}
|
||||
|
||||
event: tool-call-start
|
||||
data: {"type": "tool-call-start", "index": 0, "delta": {"message": {"tool_calls": {"id": "query_daily_sales_report_j3f0adww9pmr", "type": "function", "function": {"name": "query_daily_sales_report", "arguments": ""}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 0, "delta": {"message": {"tool_calls": {"function": {"arguments": "{\""}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 0, "delta": {"message": {"tool_calls": {"function": {"arguments": "day"}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 0, "delta": {"message": {"tool_calls": {"function": {"arguments": "\": "}}}}}
|
||||
|
||||
event: tool-call-delt)COHERE"
|
||||
R"COHERE(a
|
||||
data: {"type": "tool-call-delta", "index": 0, "delta": {"message": {"tool_calls": {"function": {"arguments": "\""}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 0, "delta": {"message": {"tool_calls": {"function": {"arguments": "2"}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 0, "delta": {"message": {"tool_calls": {"function": {"arguments": "0"}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 0, "delta": {"message": {"tool_calls": {"function": {"arguments": "2"}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 0, "delta": {"message": {"tool_calls": {"function": {"arguments": "3"}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 0, "delta": {"message": {"tool_calls": {"function": {"arguments": "-"}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 0, "delta": {"message": {"tool_calls": {"function": {"arguments": "0"}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 0, "delta": {"message": {"tool_calls": {"function": {"arguments": "9"}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 0, "delta": {"message": {"tool_calls": {"function": {"arguments": "-"}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 0, "delta": {"message": {"tool_calls": {"function": {"arguments": "2"}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 0, "delta": {"message": {"tool_calls": {"function": {"arguments": "9"}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 0, "delta": {"message": {"tool_calls": {"function": {"arguments": "\"}"}}}}}
|
||||
|
||||
event: tool-call-end
|
||||
data: {"type": "tool-call-end", "index": 0}
|
||||
|
||||
event: tool-call-start
|
||||
data: {"type": "tool-call-start", "index": 1, "delta": {"message": {"tool_calls": {"id": "query_product_catalog_c66nf11r6s8g", "type": "function", "function": {"name": "query_product_catalog", "arguments": ""}}}}}
|
||||
|
||||
event: too)COHERE"
|
||||
R"COHERE(l-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 1, "delta": {"message": {"tool_calls": {"function": {"arguments": "{\""}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 1, "delta": {"message": {"tool_calls": {"function": {"arguments": "category"}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 1, "delta": {"message": {"tool_calls": {"function": {"arguments": "\": "}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 1, "delta": {"message": {"tool_calls": {"function": {"arguments": "\""}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 1, "delta": {"message": {"tool_calls": {"function": {"arguments": "Electron"}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 1, "delta": {"message": {"tool_calls": {"function": {"arguments": "ics"}}}}}
|
||||
|
||||
event: tool-call-delta
|
||||
data: {"type": "tool-call-delta", "index": 1, "delta": {"message": {"tool_calls": {"function": {"arguments": "\"}"}}}}}
|
||||
|
||||
event: tool-call-end
|
||||
data: {"type": "tool-call-end", "index": 1}
|
||||
|
||||
event: message-end
|
||||
data: {"type": "message-end", "delta": {"finish_reason": "TOOL_CALL", "usage": {"billed_units": {"input_tokens": 126, "output_tokens": 84}, "tokens": {"input_tokens": 1589, "output_tokens": 135}}}}
|
||||
|
||||
)COHERE"
|
||||
;
|
||||
|
||||
// FIXTURE: v2/rerank example 0 response
|
||||
inline const char* kRerankV2 =
|
||||
R"COHERE({"id": "9f75d94c-5047-4f9f-ad14-4a42ef5d3ff3", "results": [{"index": 2, "relevance_score": 0.8428898, "relevant_spans": [{"start": 0, "end": 139, "score": 0.9997249}, {"start": 139, "end": 165, "score": 0.33812714}]}, {"index": 0, "relevance_score": 0.085889876, "relevant_spans": [{"start": 0, "end": 64, "score": 0.33498195}]}, {"index": 4, "relevance_score": 0.04667134, "relevant_spans": [{"start": 0, "end": 82, "score": 0.15934227}, {"start": 82, "end": 175, "score": 0.118320465}]}], "meta": {"api_version": {"version": "2"}, "billed_units": {"input_tokens": 192}}})COHERE"
|
||||
;
|
||||
|
||||
// FIXTURE: v1/tokenize example 0 response
|
||||
inline const char* kTokenize =
|
||||
R"COHERE({"tokens": [10002, 2261, 2012, 8, 2792, 43], "token_strings": ["token", "ize", " me", "!", " :", "D"], "meta": {"api_version": {"version": "1"}}})COHERE"
|
||||
;
|
||||
|
||||
// FIXTURE: v1/detokenize example 0 response
|
||||
inline const char* kDetokenize =
|
||||
R"COHERE({"text": "tokenize me! :D", "meta": {"api_version": {"version": "1"}}})COHERE"
|
||||
;
|
||||
|
||||
// FIXTURE: v1/classify example 0 response
|
||||
inline const char* kClassify =
|
||||
R"COHERE({"id": "86886163-b3f3-4e36-8554-60eca7696216", "classifications": [{"classification_type": "single-label", "confidence": 0.5661598, "confidences": [0.5661598], "id": "842d12fe-934b-4b71-82c2-c581eca00718", "input": "Confirm your email address", "labels": {"Not spam": {"confidence": 0.5661598}, "Spam": {"confidence": 0.43384025}}, "prediction": "Not spam", "predictions": ["Not spam"]}, {"classification_type": "single-label", "confidence": 0.9909811, "confidences": [0.9909811], "id": "e1a39b3e-1ecd-41d2-be75-90ed726f7b9e", "input": "hey i need u to send some $", "labels": {"Not spam": {"confidence": 0.009018883}, "Spam": {"confidence": 0.9909811}}, "prediction": "Spam", "predictions": ["Spam"]}], "meta": {"api_version": {"version": "1"}, "billed_units": {"classifications": 2}}})COHERE"
|
||||
;
|
||||
|
||||
// FIXTURE: v2/embed example 1 response
|
||||
inline const char* kEmbedV2 =
|
||||
R"COHERE({"id": "5807ee2e-0cda-445a-9ec8-864c60a06606", "texts": [], "images": [{"width": 400, "height": 400, "format": "jpeg", "bit_depth": 24}], "embeddings": {"float": [[-0.007247925, -0.041229248, -0.023223877, -0.08392334, -0.03378296, -0.008308411, -0.049926758, 0.041625977, 0.043151855, 0.03652954, -0.05154419, 0.011787415, -0.02784729, -0.024230957, -0.018295288, -0.0440979, 0.032928467, -0.015007019, 0.009315491, -0.028213501, -0.00022602081, -0.0074157715, -0.000975132, 0.05783081, 0.029510498, 0.024871826, -0.009422302, -0.028701782, -0.021118164, -0.019088745, -0.0038433075, 0.04083252, 0.03024292, -0.010154724, -0.008163452, 0.04269409, 0.017471313, -0.010017395, 0.006629944, 0.011047363, 0.013542175, -0.007926941, -0.024932861, -0.05960083, -0.05404663, 0.037384033, -0.049621582, -0.024002075, 0.040039062, 0.02645874, 0.010261536, -0.028244019, 0.016479492, 0.014266968, -0.043823242, -0.022262573, -0.0057678223, -0.04800415, 0.041015625, 0.01537323, -0.021530151, -0.014663696, 0.051849365, -0.025558472, 0.045776367, -0.025665283, -0.005821228, 0.02973938, 0.053131104, 0.020706177, -0.004600525, 0.0046920776, 0.02558899, -0.05319214, -0.058013916, 0.080444336, -0.00068187714, 0.031311035, 0.032440186, -0.051086426, -0.003534317, 0.046325684, -0.032440186, -0.03894043, -0.0071907043, -0.004627228, -0.01826477, -0.027755737, 0.040802002, 0.019363403, -0.009727478, 0.0064468384, 0.056488037, 0.018585205, -0.017974854, -0.08514404, 5.0604343e-05, -0.014839172, 0.01586914, 0.00017666817, 0.02267456, -0.05105591, 0.007785797, -0.02684021, 0.0064849854, 0.014411926, 0.0013427734, -0.012611389, 0.043701172, 0.012290955, -0.030731201, 0.034729004, 0.015289307, -0.037475586, -0.030838013, 0.010009766, -0.028244019, 0.051635742, 0.01725769, 0.013977051, 0.008102417, 0.028121948, 0.02079773, 0.0027256012, 0.009185791, 0.0016012192, -0.038116455, -0.008331299, -0.028076172, 0.018463135, -0.02154541, 0.021240234, 0.023376465, 0.02961731, -0.028305054, -0.023101807, -0.0106811)COHERE"
|
||||
R"COHERE(52, -0.0072021484, -0.04321289, 0.0058517456, 0.030792236, -0.021102905, 0.050933838, 0.0060157776, 0.0128479, 0.025146484, -0.006099701, 0.023345947, 0.023971558, 0.015510559, -0.009895325, -0.04071045, 0.049835205, 0.0053100586, -0.028930664, 0.017578125, -0.0048217773, -0.0042762756, -0.034240723, -0.03253174, 0.035827637, 0.01574707, 0.034851074, 0.070129395, 0.011749268, -0.009223938, 0.02470398, -0.005115509, 0.016723633, 0.04937744, -0.032928467, 0.031280518, -0.00023400784, 0.010169983, -0.01071167, 0.010520935, 0.022338867, -0.0259552, 0.044769287, 0.0070610046, -0.012451172, -0.04156494, 0.047088623, -0.017578125, 0.012741089, -0.016479492, 0.0023078918, -0.008331299, 0.021591187, 0.01473999, -0.018081665, 0.033081055, -0.057556152, 0.008621216, 0.013954163, -0.009742737, -0.015548706, 0.015281677, -0.005958557, 0.0065307617, 0.01979065, 0.041778564, -0.02684021, 0.027709961, -0.07672119, 0.023406982, -0.037902832, 0.035339355, -0.021881104, 0.056732178, 0.03466797, 0.0059318542, -0.058654785, 0.025375366, 0.015029907, 0.002380371, -0.024230957, 0.014541626, -0.006641388, -0.01864624, 0.012290955, 0.0007929802, -0.009277344, 0.04953003, -0.004081726, 0.0029258728, -0.017181396, 0.0074920654, -0.0001707077, 0.04220581, 0.008972168, -0.0071525574, 0.0015583038, 0.034362793, -0.019058228, 0.013626099, 0.022613525, -0.0061149597, 0.017669678, 0.015586853, 0.034973145, 0.02217102, -0.045013428, -0.009864807, 0.07244873, 0.010177612, 0.029724121, -0.018829346, -0.034057617, -0.018859863, 0.059936523, -0.0076408386, 0.021331787, -0.013786316, 0.015281677, 0.016235352, -0.039855957, -0.02748108, -0.033416748, 0.016174316, 0.026489258, 0.0049095154, -0.026000977, 0.00831604, -0.019851685, -0.021408081, 0.023010254, 0.030075073, 0.0335083, -0.05493164, 0.019515991, -0.020401001, -0.0061073303, 0.018997192, 0.020126343, -0.027740479, -0.038116455, 0.0052948, -0.008613586, -0.016494751, -0.001247406, 0.022644043, 0.008300781, -0.02104187, 0.016693115, -0.0032901764, 0)COHERE"
|
||||
R"COHERE(.012046814, -0.023468018, -0.007259369, 0.031234741, 0.06604004, 0.051635742, 0.0009441376, -0.006084442, 0.025619507, -0.006881714, 0.02999878, 0.050964355, 0.017715454, -0.024856567, -0.010070801, 0.05319214, -0.03652954, 0.011810303, -0.011978149, 0.013046265, -0.016662598, 0.017166138, -0.005542755, -0.07989502, 0.029220581, 0.056488037, 0.015914917, -0.011184692, -0.018203735, -0.03894043, -0.026626587, 0.0010070801, -0.07397461, -0.060333252, 0.046020508, -0.017440796, -0.020385742, -0.0211792, -0.018295288, -0.01802063, 0.003211975, -0.012969971, -0.034576416, -0.022079468, 0.034606934, -0.022079468, -0.02154541, -0.0039367676, 0.015419006, -0.027023315, 0.024642944, -0.0007047653, -0.008293152, 0.02708435, 0.05267334, 0.010177612, 0.017822266, -0.021759033, -0.051116943, -0.02583313, -0.06427002, 0.03213501, -0.009635925, -0.04547119, 0.018997192, -0.024032593, -0.011024475, 0.033935547, 0.050842285, 0.011009216, -0.002527237, 0.04852295, 0.038360596, -0.035583496, -0.021377563, -0.016052246, -0.072143555, 0.03665161, 0.02897644, -0.03842163, -0.00068187714, 0.022415161, -0.0030879974, 0.043762207, 0.05392456, -0.0362854, -0.04647827, -0.034057617, -0.040374756, -0.03942871, 0.030761719, -0.068115234, 0.011329651, 0.011413574, -0.012435913, 0.01576233, 0.022766113, 0.05609131, 0.07092285, 0.017593384, 0.024337769, 0.027923584, 0.06994629, 0.00655365, -0.020248413, -0.03945923, -0.0491333, -0.049194336, 0.020050049, 0.010910034, 0.013511658, 0.01676941, -0.041900635, -0.046142578, 0.012268066, 0.026748657, -0.036499023, 0.021713257, -0.036590576, 0.014411926, 0.029174805, -0.029388428, 0.04119873, 0.04852295, 0.007068634, -0.00090408325, 0.0048332214, -0.015777588, -0.01499939, -0.0068206787, -0.02708435, 0.010543823, 0.004085541, -0.026901245, -0.0045661926, 0.0061912537, -0.0014343262, 0.028945923, -0.03552246, 0.030441284, -0.029281616, 0.050628662, -0.033599854, -0.085510254, -0.052520752, -0.07507324, -0.008003235, -0.026382446, -0.078063965, -0.02516174)COHERE"
|
||||
R"COHERE(3, -0.025421143, -0.0073165894, 0.01889038, -0.05999756, -0.0051612854, 0.0072517395, -0.011497498, 0.01687622, 0.002231598, -0.034423828, -0.0013084412, -0.012413025, 0.008888245, 0.017486572, -0.03353882, 0.0069885254, -0.02722168, 0.02015686, -0.04510498, -0.038726807, -0.0031356812, 0.033233643, 0.025268555, -0.015106201, 0.02407837, -0.00024700165, -0.07409668, -0.012367249, 0.014785767, -0.04486084, 0.074401855, -0.020690918, -0.025222778, 0.029083252, -0.018997192, 0.0017557144, 0.03857422, -0.020111084, 0.03338623, -0.028213501, 0.0063705444, -0.010124207, -0.03112793, -0.03286743, 0.0046043396, -0.0052223206, 0.00023317337, 0.0423584, 0.028030396, 0.0005788803, -0.02708435, 0.006324768, 0.019821167, -0.0042686462, -0.026428223, -0.02293396, 0.036590576, -0.023376465, -0.022537231, 0.032226562, -0.020629883, 0.017929077, 0.0440979, -0.014038086, -0.022216797, 0.020446777, -0.05496216, -0.018859863, -0.039855957, 0.008300781, 0.07281494, 0.018295288, 0.042114258, 0.005519867, 0.017990112, -0.008773804, 0.011123657, -0.008239746, -0.045532227, 0.026153564, -0.015853882, 0.027557373, -0.049041748, -0.0022945404, -0.009399414, -0.045898438, 0.05053711, 0.038513184, -0.031799316, 0.012329102, 0.024871826, 0.04348755, -0.04788208, 0.01423645, 0.021240234, 0.05493164, 0.008956909, -0.056243896, 0.032043457, -0.01574707, -0.01285553, -0.009498596, -0.018951416, -0.029556274, 0.0069274902, -0.032348633, -0.022445679, -0.00093603134, -0.015808105, -0.027175903, 0.014091492, 0.025665283, -0.023468018, -0.03250122, -0.0004544258, 0.042633057, -0.06036377, -0.039611816, -0.042938232, -0.02418518, -0.0703125, 0.045135498, -0.001036644, -0.017913818, -0.004043579, 0.0138549805, -0.02532959, 0.010765076, 0.021575928, 0.013114929, 0.033935547, -0.010574341, 0.017990112, -0.026107788, -0.029144287, -0.046569824, -0.0030517578, -0.022994995, -0.017471313, -0.0070495605, -9.846687e-05, 0.029281616, 0.017440796, 0.045532227, 0.025650024, 0.0491333, -0.013145447, 0.070129395, -0.)COHERE"
|
||||
R"COHERE(0051879883, -0.04043579, 0.023864746, 0.016830444, -0.014152527, -0.06359863, -0.005065918, -0.009880066, -0.0034618378, -0.081726074, -0.0289917, -0.007461548, -0.0013504028, 0.020523071, 0.0076446533, -0.011650085, 0.014549255, 0.010955811, 0.02180481, -0.027572632, -0.012252808, 0.009033203, -0.0048980713, 0.031173706, -0.020309448, 0.022979736, -0.013900757, -0.004108429, 0.018325806, -0.031402588, 0.01737976, 0.03201294, -0.02508545, -0.015625, -0.04626465, -0.014656067, 0.016036987, -0.030639648, 0.041748047, -0.0032978058, -0.03277588, 0.037719727, 0.023788452, -0.008140564, -0.041809082, 0.034698486, -0.022994995, -0.009979248, -0.03729248, -0.0904541, 0.00028443336, 0.080566406, -0.035125732, -0.054229736, -0.017700195, 0.060668945, 0.008979797, 0.015052795, -0.0072364807, -0.001490593, 0.0065231323, -0.014579773, 0.016067505, -0.020339966, -0.020217896, 0.02909851, 0.050628662, 0.04510498, -0.01979065, 0.008918762, 0.031799316, 0.031951904, -0.016906738, 0.031036377, 0.0040664673, -0.046905518, -0.04928589, 0.044403076, -0.0524292, -0.012832642, 0.049835205, 0.0040283203, -0.012649536, 0.06878662, -0.02859497, -0.014137268, 0.0036144257, -0.06262207, 0.046813965, 0.024978638, 0.0017976761, -0.032409668, -0.004108429, -0.013557434, -0.07196045, 0.026733398, 0.0024261475, -0.022735596, -0.0022182465, -0.0064315796, -0.03652954, 0.04135132, -0.032562256, 0.004524231, 0.020019531, -0.0113220215, -0.071777344, -0.03451538, 0.0022583008, -0.06512451, -0.005317688, 0.020248413, -0.036712646, 0.005809784, -0.018951416, -0.0026855469, 0.027572632, -0.00036668777, 0.0073623657, -0.018829346, 0.009101868, 0.051971436, 0.023132324, -0.022537231, 0.00932312, 0.00944519, 0.014183044, 0.020889282, 0.0032844543, -0.0073776245, -0.05807495, -0.032440186, 0.033996582, 0.0423584, 0.014259338, 0.061676025, -0.02154541, -0.031982422, 0.005493164, -0.01512146, 0.023101807, -0.011383057, -0.059539795, 0.021820068, 0.015487671, -0.004875183, -0.015640259, 0.015319824, -0.00543594)COHERE"
|
||||
R"COHERE(36, -0.026229858, 0.0061454773, -0.032348633, 0.038513184, 0.004840851, -0.016021729, -0.017608643, -0.019577026, -0.009178162, 0.045013428, -0.01007843, 0.022323608, 0.034179688, 0.00566864, 0.055511475, -0.033355713, -0.019317627, -8.481741e-05, 0.017547607, -0.053344727, 0.012229919, 0.022384644, 0.018051147, 0.010734558, 0.004501343, -0.05911255, -0.0030918121, -0.0513916, -0.0050086975, -0.01600647, 0.05343628, -0.0008234978, 0.07293701, -0.056610107, -0.06549072, -0.01776123, -0.0022678375, 0.023239136, 0.01020813, -0.005153656, -0.00630188, -0.009880066, 0.022109985, 0.033203125, -0.03567505, -0.014129639, 0.015625, 0.022888184, -0.038726807, -0.026321411, -0.007259369, 0.005924225, 0.0010814667, 0.06665039, -0.008880615, 0.053771973, 0.062194824, 0.018981934, 0.022338867, 0.01361084, 0.025604248, 0.022109985, 0.0044288635, -0.008331299, -0.0019416809, 0.006454468, -0.045013428, -0.02519226, -0.012268066, -0.032165527, 7.2181225e-05, -0.021575928, -0.006324768, 0.029785156, 0.0063438416, -0.01210022, 0.029403687, 0.00592041, 0.008369446, 0.00818634, -0.04498291, -0.041809082, 0.0078086853, -0.05935669, -0.043518066, 0.007270813, 0.060424805, 0.033996582, 0.055908203, 0.013755798, 0.03982544, 0.014640808, -0.01373291, 0.033325195, -0.0047073364, 0.015899658, -0.00043344498, 0.022338867, -0.007095337, 0.02949524, 0.042633057, 0.030670166, 0.022415161, -0.0033683777, 0.018814087, -0.013031006, 0.031951904, 0.022094727, -0.009986877, 0.025665283, -0.0138168335, 0.049743652, 0.024307251, 0.0088272095, -0.03479004, 0.07318115, 0.009849548, 0.051635742, -0.05331421, -0.053131104, -0.0044898987, 0.029342651, 0.005596161, 0.044189453, -0.042388916, -0.012939453, -0.0007529259, -0.06088257, 0.036010742, -0.02355957, 0.004497528, -0.0023822784, -0.053588867, -0.04168701, -0.017868042, -0.01927185, -0.06011963, 0.028884888, 0.061401367, -0.005584717, 0.014823914, -0.02255249, 4.631281e-05, 0.039031982, -0.0055389404, 0.007194519, 0.0037631989, 0.008834839, 0.018692017, 0)COHERE"
|
||||
R"COHERE(.033111572, -0.056274414, -0.021774292, 0.04727173, -0.03265381, 0.022140503, 0.027801514, 0.004043579, -0.016525269, -0.041809082, 0.024520874, 0.008529663, 0.049072266, 0.033447266, -0.028839111, 0.048675537, 0.021453857, -0.08087158, 0.034606934, -0.002910614, 0.012176514, 0.035705566, 0.040161133, -0.02355957, -0.01626587, -0.033721924, -0.013893127, -0.04156494, 0.06719971, 0.043151855, -0.033813477, 0.028045654, 0.0029525757, -0.022033691, -0.093811035, -0.0056114197, 0.00026154518, 0.058746338, -0.05065918, 0.02897644, -0.01550293, -0.02947998, -0.018249512, 0.034942627, -0.04574585, -0.037109375, -0.006160736, 0.006149292, -0.0012207031, -0.042907715, -0.016448975, 0.0052719116, 0.036590576, -0.045318604, -0.04220581, -0.018859863, -0.031021118, 0.06439209, -0.0056533813, -0.037200928, -0.026550293, 0.027786255, -0.028427124, 0.09161377, -0.0088272095, -0.003643036, -0.053253174, -0.01826477, -0.016540527, -0.012535095, -0.03942871, -0.0049095154, 0.031311035, 0.049468994, -0.066589355, -0.05029297, 7.5519085e-05, -0.0017404556, -0.013214111, -0.03756714, -0.009147644, -0.025466919, 0.026672363, 0.020965576, -0.0073432922, 0.0011005402, -0.04937744, -0.018463135, 0.00274086, -0.013252258, 0.0126953125, -0.077697754, 0.014045715, 0.00039935112, -0.019515991, -0.0027618408, -0.011672974, -0.043884277, 0.009231567, 0.062805176, -0.0137786865, -0.026229858, -0.034362793, -0.015090942, 0.016937256, 0.030639648, -0.02420044, 0.02482605, -0.0033740997, 0.046417236, -0.012008667, -0.04031372, -0.00032520294, 0.01525116, -0.0066375732, 0.0062713623, -0.01171875, -0.027191162, -0.014137268, -0.025390625, 0.002111435, -0.06561279, 0.031555176, -0.07519531, -0.04547119, 0.014472961, -0.0158844, -0.091552734, -0.03366089, 0.050323486, -0.0013589859, -0.033203125, 0.046539307, -0.030288696, 0.0046195984, 0.049835205, 0.02003479, -0.004196167, 0.013168335, -0.016403198, 0.01676941, -0.00340271]]}, "meta": {"api_version": {"version": "2"}, "billed_units": {"images": 1}}})COHERE"
|
||||
;
|
||||
|
||||
// FIXTURE: v1/summarize example 0 response
|
||||
inline const char* kSummarize =
|
||||
R"COHERE({"id": "aa0b828e-f9cf-484d-a84d-cb62f556e841", "summary": "Ice cream is a frozen dessert made by whipping a cream base and liquid nitrogen together. It is then flavoured with sweeteners, spices and fruits. Ice cream can also be made using alternative milks, such as soy or almond, for those who are lactose intolerant or vegan.", "meta": {"api_version": {"version": "1"}, "billed_units": {"input_tokens": 321, "output_tokens": 55}}})COHERE"
|
||||
;
|
||||
|
||||
} // namespace cohere_test
|
||||
Vendored
+51
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
// Shared rig for the Cohere tests: a Platform over a MockTransport with a fake
|
||||
// key. The mock only records the requests the real client builds; replies are
|
||||
// the spec's documented examples (fixtures.h, verbatim) or minimal documents
|
||||
// shaped from the OpenAPI schemas and labelled SHAPE where they appear. Nothing
|
||||
// here verifies vendor behavior (see src/vendors/cohere/SPEC.md ## Unverified).
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "clients/transports/mock_transport.h"
|
||||
#include "fixtures.h"
|
||||
#include "framework.h"
|
||||
#include "vendors/cohere/platform.h"
|
||||
|
||||
namespace cohere_test {
|
||||
|
||||
using molo::clients::ClientResponse;
|
||||
using molo::clients::HeaderMap;
|
||||
using molo::clients::Method;
|
||||
using molo::clients::transports::MockExpectation;
|
||||
using molo::clients::transports::MockTransport;
|
||||
using Json = molo::clients::body::Json;
|
||||
|
||||
inline ClientResponse reply(const std::string& body, int status = 200,
|
||||
const std::string& type = "application/json") {
|
||||
HeaderMap h;
|
||||
h.set("Content-Type", type);
|
||||
return ClientResponse(status, h, body);
|
||||
}
|
||||
|
||||
inline ClientResponse sse(const std::string& body) { return reply(body, 200, "text/event-stream"); }
|
||||
|
||||
inline bool has(const std::string& hay, const std::string& needle) { return hay.find(needle) != std::string::npos; }
|
||||
|
||||
inline const char* kKey = "co-TESTKEY-DO-NOT-LEAK";
|
||||
|
||||
struct Rig {
|
||||
MockTransport* mock = nullptr;
|
||||
molo::cohere::Platform platform;
|
||||
|
||||
explicit Rig(const std::string& key = kKey) {
|
||||
auto t = std::make_unique<MockTransport>();
|
||||
mock = t.get();
|
||||
platform = molo::cohere::Platform::with(std::move(t), key);
|
||||
}
|
||||
std::shared_ptr<molo::llm::ApiClient> client() const { return platform.client; }
|
||||
};
|
||||
|
||||
} // namespace cohere_test
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
// The call table: shape, rendering, id and query validation, body checks.
|
||||
#include <set>
|
||||
|
||||
#include "support.h"
|
||||
#include "vendors/cohere/calls.h"
|
||||
#include "vendors/cohere/catalog.h"
|
||||
|
||||
using namespace molo::cohere;
|
||||
using namespace cohere_test;
|
||||
using molo::llm::ApiError;
|
||||
|
||||
TEST(cohere_calls, every_enum_value_has_exactly_one_row) {
|
||||
ASSERT_EQ(Calls::count(), 42u);
|
||||
std::set<int> seen;
|
||||
std::set<std::string> routes;
|
||||
for (std::size_t i = 0; i < Calls::count(); ++i) {
|
||||
const CallSpec& s = Calls::at(i);
|
||||
ASSERT_TRUE(seen.insert(static_cast<int>(s.call)).second);
|
||||
ASSERT_TRUE(routes.insert(std::string(s.http_method) + " " + s.path).second);
|
||||
ASSERT_EQ(&Calls::spec_of(s.call), &s);
|
||||
ASSERT_TRUE(std::string(s.path).rfind("/v", 0) == 0);
|
||||
ASSERT_TRUE(std::string(s.operation_id).size() > 0);
|
||||
}
|
||||
ASSERT_EQ(seen.size(), Calls::count());
|
||||
ASSERT_TRUE(Calls::schema_count() > 60);
|
||||
ASSERT_THROW(Calls::at(Calls::count()), ApiError);
|
||||
ASSERT_THROW(Calls::schema_at(Calls::schema_count()), ApiError);
|
||||
}
|
||||
|
||||
TEST(cohere_calls, render_fills_the_placeholder_with_a_validated_id) {
|
||||
ASSERT_EQ(Calls::render(Call::kBatchGet, "b-1"), "/v2/batches/b-1");
|
||||
ASSERT_EQ(Calls::render(Call::kBatchCancel, "b-1"), "/v2/batches/b-1:cancel");
|
||||
ASSERT_EQ(Calls::render(Call::kFinetuneEvents, "ft_1"), "/v1/finetuning/finetuned-models/ft_1/events");
|
||||
ASSERT_EQ(Calls::render(Call::kModelGet, "command-a-03-2025"), "/v1/models/command-a-03-2025");
|
||||
ASSERT_THROW(Calls::render(Call::kBatchGet, ""), ApiError);
|
||||
ASSERT_THROW(Calls::render(Call::kBatchGet, "../x"), ApiError);
|
||||
ASSERT_THROW(Calls::render(Call::kBatchGet, "a/b"), ApiError);
|
||||
ASSERT_THROW(Calls::render(Call::kBatchGet, "a?b=1"), ApiError);
|
||||
ASSERT_THROW(Calls::render(Call::kChat, "x"), ApiError); // takes no id
|
||||
}
|
||||
|
||||
TEST(cohere_calls, query_names_must_be_in_the_row_and_are_encoded) {
|
||||
Query q = {{"page_size", "5"}, {"order_by", "created at"}};
|
||||
ASSERT_EQ(Calls::render(Call::kBatchList, "", q), "/v2/batches?page_size=5&order_by=created%20at");
|
||||
Query repeated = {{"keep_fields", "a"}, {"keep_fields", "b"}, {"name", "n"}, {"type", "embed-input"}};
|
||||
ASSERT_TRUE(has(Calls::render(Call::kDatasetCreate, "", repeated), "keep_fields=a&keep_fields=b"));
|
||||
ASSERT_THROW(Calls::render(Call::kBatchList, "", Query{{"nope", "1"}}), ApiError);
|
||||
ASSERT_THROW(Calls::render(Call::kChat, "", Query{{"page_size", "1"}}), ApiError);
|
||||
}
|
||||
|
||||
TEST(cohere_calls, check_body_rejects_fields_outside_the_row) {
|
||||
Json ok = Json::parse("{\"model\":\"m\",\"messages\":[]}");
|
||||
Calls::check_body(Call::kChat, ok);
|
||||
Json bad = Json::parse("{\"model\":\"m\",\"max_completion_tokens\":5}");
|
||||
ASSERT_THROW(Calls::check_body(Call::kChat, bad), ApiError);
|
||||
ASSERT_THROW(Calls::check_body(Call::kChat, Json::parse("[1]")), ApiError);
|
||||
}
|
||||
|
||||
TEST(cohere_calls, methods_map_from_the_table) {
|
||||
ASSERT_TRUE(Calls::method_of(Call::kChat) == Method::kPost);
|
||||
ASSERT_TRUE(Calls::method_of(Call::kModelList) == Method::kGet);
|
||||
ASSERT_TRUE(Calls::method_of(Call::kConnectorUpdate) == Method::kPatch);
|
||||
ASSERT_TRUE(Calls::method_of(Call::kDatasetDelete) == Method::kDelete);
|
||||
}
|
||||
|
||||
TEST(cohere_catalog, names_and_status) {
|
||||
ASSERT_TRUE(ModelCatalog::count() >= 15);
|
||||
ASSERT_TRUE(ModelCatalog::status_of("command-a-03-2025") == ModelStatus::kLive);
|
||||
ASSERT_TRUE(ModelCatalog::status_of("command-r-03-2024") == ModelStatus::kDeprecated);
|
||||
ASSERT_TRUE(ModelCatalog::status_of("nonsense") == ModelStatus::kUnknown);
|
||||
ASSERT_EQ(std::string(ModelCatalog::default_chat()), "command-a-03-2025");
|
||||
ASSERT_EQ(std::string(ModelCatalog::default_embed()), "embed-v4.0");
|
||||
ASSERT_EQ(std::string(ModelCatalog::default_rerank()), "rerank-v3.5");
|
||||
ASSERT_THROW(ModelCatalog::at(ModelCatalog::count()), ApiError);
|
||||
}
|
||||
+304
@@ -0,0 +1,304 @@
|
||||
// Cohere chat v2 over the real ApiClient with a recording transport. Replies
|
||||
// are the spec's documented examples (fixtures.h); assertions are on what WE
|
||||
// send and on how WE parse.
|
||||
#include "support.h"
|
||||
#include "vendors/cohere/chat.h"
|
||||
|
||||
using namespace molo::cohere;
|
||||
using namespace cohere_test;
|
||||
using molo::llm::ApiError;
|
||||
|
||||
TEST(cohere_chat, create_sends_bearer_json_and_parses_the_documented_example) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v2/chat", reply(kChatBasic));
|
||||
Chat chat(rig.client());
|
||||
ChatParams p = ChatParams::prompt("Tell me about LLMs");
|
||||
p.model = "command-a-plus-05-2026";
|
||||
ChatResult r = chat.create(p);
|
||||
ASSERT_EQ(r.id, "c14c80c3-18eb-4519-9460-6c92edd8cfb4");
|
||||
ASSERT_EQ(r.finish_reason, "COMPLETE");
|
||||
ASSERT_TRUE(has(r.text, "LLMs stand for Large Language Models"));
|
||||
ASSERT_TRUE(r.usage.present);
|
||||
ASSERT_TRUE(r.usage.input_tokens > 0 && r.usage.output_tokens > 0);
|
||||
ASSERT_TRUE(r.usage.billed_input_tokens > 0);
|
||||
auto s = rig.mock->seen()[0];
|
||||
ASSERT_EQ(s.method, "POST");
|
||||
ASSERT_EQ(s.target, "/v2/chat");
|
||||
ASSERT_EQ(s.headers.get_or("Authorization", ""), std::string("Bearer ") + kKey);
|
||||
ASSERT_EQ(s.headers.get_or("X-Client-Name", ""), "molo");
|
||||
ASSERT_TRUE(has(s.headers.get_or("Content-Type", ""), "application/json"));
|
||||
ASSERT_TRUE(has(s.body, "\"model\":\"command-a-plus-05-2026\""));
|
||||
ASSERT_TRUE(has(s.body, "\"messages\":[{\"content\":\"Tell me about LLMs\",\"role\":\"user\"}]"));
|
||||
ASSERT_FALSE(has(s.body, "\"stream\""));
|
||||
ASSERT_EQ(s.target.find(kKey), std::string::npos);
|
||||
}
|
||||
|
||||
TEST(cohere_chat, tool_call_with_thinking_documented_example) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v2/chat", reply(kChatToolThinking));
|
||||
ChatResult r = Chat(rig.client()).create(ChatParams::prompt("sales?"));
|
||||
ASSERT_EQ(r.finish_reason, "TOOL_CALL");
|
||||
ASSERT_TRUE(has(r.thinking, "sales summary for 29th September 2023"));
|
||||
ASSERT_EQ(r.text, "");
|
||||
ASSERT_EQ(r.tool_calls.size(), 2u);
|
||||
ASSERT_EQ(r.tool_calls[0].name, "query_daily_sales_report");
|
||||
ASSERT_TRUE(r.tool_calls[0].arguments_valid());
|
||||
ASSERT_EQ(r.tool_calls[0].parsed().find("day")->as_string(), "2023-09-29");
|
||||
ASSERT_EQ(r.tool_calls[1].id, "query_product_catalog_rpg0z5h8yyz2");
|
||||
ASSERT_EQ(r.usage.input_tokens, 1032);
|
||||
ASSERT_EQ(r.usage.output_tokens, 124);
|
||||
ASSERT_EQ(r.usage.billed_input_tokens, 127);
|
||||
// The history message keeps thinking, tool_calls and no empty text.
|
||||
Json h = r.history_message();
|
||||
ASSERT_EQ(h.find("role")->as_string(), "assistant");
|
||||
ASSERT_EQ(h.find("tool_calls")->as_array().size(), 2u);
|
||||
ASSERT_EQ(h.find("content")->as_array()[0].find("type")->as_string(), "thinking");
|
||||
}
|
||||
|
||||
TEST(cohere_chat, citations_documented_example) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v2/chat", reply(kChatCitations));
|
||||
ChatParams p = ChatParams::prompt("Who is more popular?");
|
||||
p.documents.push_back(Json("a plain string document"));
|
||||
p.citation_mode = "FAST";
|
||||
ChatResult r = Chat(rig.client()).create(p);
|
||||
ASSERT_TRUE(!r.citations.empty());
|
||||
ASSERT_TRUE(r.citations[0].find("sources") != nullptr);
|
||||
ASSERT_TRUE(has(rig.mock->seen()[0].body, "\"citation_options\":{\"mode\":\"FAST\"}"));
|
||||
ASSERT_TRUE(has(rig.mock->seen()[0].body, "\"documents\":[\"a plain string document\"]"));
|
||||
}
|
||||
|
||||
TEST(cohere_chat, stream_documented_text_transcript) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v2/chat", sse(kStreamText));
|
||||
Chat chat(rig.client());
|
||||
std::string text;
|
||||
int starts = 0, ends = 0;
|
||||
ChatResult r = chat.stream(ChatParams::prompt("Tell me about LLMs"), [&](const StreamDelta& d) {
|
||||
text += d.text;
|
||||
if (d.type == "message-start") ++starts;
|
||||
if (d.type == "message-end") {
|
||||
++ends;
|
||||
ASSERT_TRUE(d.has_usage);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
ASSERT_EQ(starts, 1);
|
||||
ASSERT_EQ(ends, 1);
|
||||
ASSERT_TRUE(has(text, "LLMs stand for Large Language Models"));
|
||||
ASSERT_EQ(r.text, text);
|
||||
ASSERT_EQ(r.id, "29f14a5a-11de-4cae-9800-25e4747408ea");
|
||||
ASSERT_TRUE(r.finish_reason == "COMPLETE");
|
||||
auto s = rig.mock->seen()[0];
|
||||
ASSERT_TRUE(has(s.body, "\"stream\":true"));
|
||||
ASSERT_TRUE(has(s.headers.get_or("Accept", ""), "text/event-stream"));
|
||||
}
|
||||
|
||||
TEST(cohere_chat, stream_documented_tool_transcript_folds_plan_and_calls) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v2/chat", sse(kStreamTools));
|
||||
Chat chat(rig.client());
|
||||
std::string plan;
|
||||
int tool_starts = 0;
|
||||
ChatResult r = chat.stream(ChatParams::prompt("sales"), [&](const StreamDelta& d) {
|
||||
plan += d.tool_plan;
|
||||
if (d.tool_start) ++tool_starts;
|
||||
return true;
|
||||
});
|
||||
ASSERT_TRUE(has(plan, "I will use the query_daily_sales_report tool"));
|
||||
ASSERT_EQ(r.tool_plan, plan);
|
||||
ASSERT_EQ(r.finish_reason, "TOOL_CALL");
|
||||
ASSERT_TRUE(tool_starts >= 2);
|
||||
ASSERT_EQ(r.tool_calls.size(), static_cast<std::size_t>(tool_starts));
|
||||
for (const ToolCallRecord& c : r.tool_calls) {
|
||||
ASSERT_TRUE(!c.id.empty() && !c.name.empty());
|
||||
ASSERT_TRUE(c.arguments_valid());
|
||||
}
|
||||
ASSERT_EQ(r.usage.input_tokens, 1589);
|
||||
}
|
||||
|
||||
TEST(cohere_chat, sink_can_stop_the_stream_early) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v2/chat", sse(kStreamText));
|
||||
int n = 0;
|
||||
ChatResult r = Chat(rig.client()).stream(ChatParams::prompt("hi"), [&](const StreamDelta&) { return ++n < 4; });
|
||||
ASSERT_EQ(n, 4);
|
||||
ASSERT_TRUE(r.finish_reason.empty());
|
||||
}
|
||||
|
||||
TEST(cohere_chat, stream_without_message_end_is_loud) {
|
||||
Rig rig;
|
||||
const std::string cut =
|
||||
"event: message-start\ndata: {\"type\":\"message-start\",\"id\":\"x\",\"delta\":{\"message\":{\"role\":\"assistant\"}}}\n\n";
|
||||
rig.mock->expect_response(Method::kPost, "/v2/chat", sse(cut));
|
||||
try {
|
||||
Chat(rig.client()).stream(ChatParams::prompt("hi"), nullptr);
|
||||
FAIL("expected");
|
||||
} catch (const ApiError& e) {
|
||||
ASSERT_EQ(e.type(), "STREAM_TRUNCATED");
|
||||
ASSERT_EQ(e.http_status(), 502);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(cohere_chat, message_end_error_and_json_error_body_throw) {
|
||||
Rig rig;
|
||||
const std::string err =
|
||||
"event: message-end\ndata: {\"type\":\"message-end\",\"delta\":{\"error\":\"model overloaded\",\"finish_reason\":\"ERROR\"}}\n\n";
|
||||
rig.mock->expect_response(Method::kPost, "/v2/chat", sse(err));
|
||||
try {
|
||||
Chat(rig.client()).stream(ChatParams::prompt("hi"), nullptr);
|
||||
FAIL("expected");
|
||||
} catch (const ApiError& e) {
|
||||
ASSERT_EQ(e.type(), "STREAM_ERROR");
|
||||
ASSERT_TRUE(has(e.message(), "overloaded"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(cohere_chat, http_error_keeps_status_and_message_without_the_key) {
|
||||
Rig rig;
|
||||
// PROBE: shape of the unauthenticated answer seen 2026-10-25 (body {"id","message"}).
|
||||
rig.mock->expect_response(Method::kPost, "/v2/chat",
|
||||
reply("{\"id\":\"0045bb6a-672c-459a-937b-54654beeb342\",\"message\":\"Incorrect API key provided: ***robe.\"}", 401));
|
||||
try {
|
||||
Chat(rig.client()).create(ChatParams::prompt("hi"));
|
||||
FAIL("expected");
|
||||
} catch (const ApiError& e) {
|
||||
ASSERT_EQ(e.http_status(), 401);
|
||||
ASSERT_TRUE(has(e.message(), "Incorrect API key"));
|
||||
ASSERT_EQ(e.message().find(kKey), std::string::npos);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(cohere_chat, not_configured_has_no_traffic) {
|
||||
Rig rig("");
|
||||
try {
|
||||
Chat(rig.client()).create(ChatParams::prompt("hi"));
|
||||
FAIL("expected");
|
||||
} catch (const molo::llm::NotConfiguredError& e) {
|
||||
ASSERT_EQ(e.http_status(), 503);
|
||||
ASSERT_TRUE(has(e.message(), "COHERE_API_KEY"));
|
||||
}
|
||||
ASSERT_EQ(rig.mock->send_count(), 0u);
|
||||
ASSERT_FALSE(rig.platform.configured());
|
||||
}
|
||||
|
||||
TEST(cohere_chat, invalid_input_never_reaches_the_network) {
|
||||
Rig rig;
|
||||
Chat chat(rig.client());
|
||||
auto bad = [&](auto mutate) {
|
||||
ChatParams p = ChatParams::prompt("hi");
|
||||
mutate(p);
|
||||
ASSERT_THROW(chat.create(p), ApiError);
|
||||
};
|
||||
ASSERT_THROW(chat.create(ChatParams()), ApiError); // no messages
|
||||
bad([](ChatParams& p) { p.model = ""; });
|
||||
bad([](ChatParams& p) { p.model = "a b"; });
|
||||
bad([](ChatParams& p) { p.temperature = 1.5; });
|
||||
bad([](ChatParams& p) { p.p = 1.0; });
|
||||
bad([](ChatParams& p) { p.p = 0.0; });
|
||||
bad([](ChatParams& p) { p.k = 501; });
|
||||
bad([](ChatParams& p) { p.priority = 1000; });
|
||||
bad([](ChatParams& p) { p.max_tokens = 0; });
|
||||
bad([](ChatParams& p) { p.frequency_penalty = 1.1; });
|
||||
bad([](ChatParams& p) { p.seed = -1; });
|
||||
bad([](ChatParams& p) { p.stop = {"a", "b", "c", "d", "e", "f"}; });
|
||||
bad([](ChatParams& p) { p.stop = {""}; });
|
||||
bad([](ChatParams& p) { p.tool_choice = "AUTO"; });
|
||||
bad([](ChatParams& p) { p.tool_choice = "REQUIRED"; }); // needs tools
|
||||
bad([](ChatParams& p) { p.strict_tools = true; }); // needs tools
|
||||
bad([](ChatParams& p) { p.safety_mode = "LOOSE"; });
|
||||
bad([](ChatParams& p) { p.citation_mode = "MAYBE"; });
|
||||
bad([](ChatParams& p) { p.thinking_budget = 100; }); // needs thinking enabled
|
||||
bad([](ChatParams& p) { p.json_schema = Json::object(); }); // needs json_mode
|
||||
bad([](ChatParams& p) { p.extra = Json::parse("{\"unknown\":1}"); });
|
||||
bad([](ChatParams& p) { p.messages.assign(4097, Messages::user("x")); });
|
||||
bad([](ChatParams& p) { p.tools.resize(1); }); // empty tool name
|
||||
ASSERT_THROW(Messages::image_part("ftp://x"), ApiError);
|
||||
ASSERT_THROW(Messages::tool("", "x"), ApiError);
|
||||
ASSERT_THROW(Messages::user_parts({}), ApiError);
|
||||
ASSERT_EQ(rig.mock->send_count(), 0u);
|
||||
}
|
||||
|
||||
TEST(cohere_chat, every_optional_field_lands_in_the_body_and_in_the_table) {
|
||||
ChatParams p = ChatParams::prompt("hi");
|
||||
p.add(Messages::system("be brief"));
|
||||
p.tools.push_back(ToolDef{"get_weather", "Weather", Json::parse("{\"type\":\"object\"}")});
|
||||
p.strict_tools = true;
|
||||
p.documents.push_back(Json::parse("{\"id\":\"d1\",\"data\":{\"title\":\"t\"}}"));
|
||||
p.citation_mode = "ACCURATE";
|
||||
p.json_mode = true;
|
||||
p.json_schema = Json::parse("{\"type\":\"object\"}");
|
||||
p.safety_mode = "STRICT";
|
||||
p.max_tokens = 100;
|
||||
p.stop = {"END"};
|
||||
p.temperature = 0.3;
|
||||
p.seed = 7;
|
||||
p.frequency_penalty = 0.1;
|
||||
p.presence_penalty = 0.2;
|
||||
p.k = 40;
|
||||
p.p = 0.75;
|
||||
p.logprobs = true;
|
||||
p.tool_choice = "REQUIRED";
|
||||
p.thinking = Thinking::kEnabled;
|
||||
p.thinking_budget = 2048;
|
||||
p.priority = 5;
|
||||
Json b = p.to_json(true);
|
||||
for (const char* k : {"model", "messages", "stream", "tools", "strict_tools", "documents", "citation_options",
|
||||
"response_format", "safety_mode", "max_tokens", "stop_sequences", "temperature", "seed",
|
||||
"frequency_penalty", "presence_penalty", "k", "p", "logprobs", "tool_choice", "thinking",
|
||||
"priority"})
|
||||
ASSERT_TRUE(b.find(k) != nullptr);
|
||||
ASSERT_EQ(b.find("thinking")->find("token_budget")->as_int(), 2048);
|
||||
ASSERT_EQ(b.find("response_format")->find("type")->as_string(), "json_object");
|
||||
ASSERT_EQ(b.find("tools")->as_array()[0].find("function")->find("name")->as_string(), "get_weather");
|
||||
Calls::check_body(Call::kChat, b);
|
||||
}
|
||||
|
||||
TEST(cohere_chat, conversation_runs_the_tool_loop_with_a_round_cap) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v2/chat", reply(kChatToolThinking));
|
||||
rig.mock->expect_response(Method::kPost, "/v2/chat", reply(kChatBasic));
|
||||
ChatParams base = ChatParams::prompt("sales summary and electronics?");
|
||||
ToolDef t;
|
||||
t.name = "query_daily_sales_report";
|
||||
base.tools.push_back(t);
|
||||
Conversation conv(base);
|
||||
std::vector<std::string> called;
|
||||
ChatResult r = conv.run_tools(*std::make_unique<Chat>(rig.client()),
|
||||
[&](const std::string& name, const Json& args, const std::string& id) {
|
||||
called.push_back(name + ":" + id);
|
||||
ASSERT_TRUE(args.is_object());
|
||||
return std::string("{\"ok\":true}");
|
||||
});
|
||||
ASSERT_EQ(called.size(), 2u);
|
||||
ASSERT_TRUE(has(r.text, "LLMs stand for"));
|
||||
// history: user, assistant(tool_calls), tool, tool, assistant
|
||||
ASSERT_EQ(conv.params().messages.size(), 5u);
|
||||
ASSERT_EQ(conv.params().messages[2].find("role")->as_string(), "tool");
|
||||
ASSERT_EQ(conv.params().messages[2].find("tool_call_id")->as_string(), "query_daily_sales_report_hgxxmkby3wta");
|
||||
ASSERT_TRUE(has(rig.mock->seen()[1].body, "\"tool_call_id\""));
|
||||
|
||||
// a model that never stops asking for tools hits the cap
|
||||
Rig loop;
|
||||
for (int i = 0; i < 2; ++i) loop.mock->expect_response(Method::kPost, "/v2/chat", reply(kChatToolThinking));
|
||||
Conversation again(base);
|
||||
Chat chat2(loop.client());
|
||||
ASSERT_THROW(again.run_tools(chat2, [](const std::string&, const Json&, const std::string&) { return std::string("x"); }, 2),
|
||||
ApiError);
|
||||
ASSERT_EQ(loop.mock->send_count(), 2u);
|
||||
ASSERT_THROW(again.run_tools(chat2, nullptr, 17), ApiError);
|
||||
ASSERT_THROW(Conversation(ChatParams::prompt("x")).run_tools(chat2, nullptr), ApiError); // no tools
|
||||
}
|
||||
|
||||
TEST(cohere_chat, legacy_v1_chat_checks_fields_against_the_table) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v1/chat", reply("{\"text\":\"hi\",\"generation_id\":\"g\",\"finish_reason\":\"COMPLETE\"}"));
|
||||
Chat chat(rig.client());
|
||||
Json out = chat.legacy(Json::parse("{\"message\":\"hello\",\"preamble\":\"be nice\"}"));
|
||||
ASSERT_EQ(out.find("text")->as_string(), "hi");
|
||||
ASSERT_TRUE(has(rig.mock->seen()[0].body, "\"message\":\"hello\""));
|
||||
ASSERT_THROW(chat.legacy(Json::parse("{\"prompt\":\"x\"}")), ApiError);
|
||||
ASSERT_THROW(chat.legacy(Json::parse("{\"message\":\"x\",\"stream\":true}")), ApiError);
|
||||
ASSERT_THROW(chat.legacy(Json::parse("{\"message\":\"x\",\"bogus\":1}")), ApiError);
|
||||
ASSERT_EQ(rig.mock->send_count(), 1u);
|
||||
}
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
// CohereChatModel: the neutral ChatModel mapping, offline. The neutral request
|
||||
// is mapped to wire parameters and back; the transport only records.
|
||||
#include "llm/chat_types.h"
|
||||
#include "support.h"
|
||||
#include "vendors/cohere/chat_model.h"
|
||||
|
||||
using namespace molo::cohere;
|
||||
using namespace cohere_test;
|
||||
using molo::llm::ApiError;
|
||||
|
||||
namespace {
|
||||
CohereChatModel make(Rig& rig) { return CohereChatModel(std::make_shared<Chat>(rig.client())); }
|
||||
} // namespace
|
||||
|
||||
TEST(cohere_model, vendor_and_defaults) {
|
||||
Rig rig;
|
||||
CohereChatModel m = make(rig);
|
||||
ASSERT_EQ(m.vendor(), "cohere");
|
||||
molo::llm::ChatRequest r;
|
||||
r.messages.push_back(molo::llm::Message::user("hi"));
|
||||
ASSERT_EQ(m.to_params(r).model, "command-a-03-2025");
|
||||
r.model = "command-r7b-12-2024";
|
||||
ASSERT_EQ(m.to_params(r).model, "command-r7b-12-2024");
|
||||
}
|
||||
|
||||
TEST(cohere_model, request_mapping_system_tools_json_and_sampling) {
|
||||
Rig rig;
|
||||
CohereChatModel m = make(rig);
|
||||
molo::llm::ChatRequest r;
|
||||
r.system = "be brief";
|
||||
r.messages.push_back(molo::llm::Message::user("weather?"));
|
||||
molo::llm::ToolSpec t;
|
||||
t.name = "get_weather";
|
||||
t.description = "Weather";
|
||||
t.parameters = Json::parse("{\"type\":\"object\"}");
|
||||
r.tools.push_back(t);
|
||||
r.tool_choice = "required";
|
||||
r.max_tokens = 50;
|
||||
r.temperature = 0.2;
|
||||
r.top_p = 0.9;
|
||||
r.stop = {"END"};
|
||||
r.json_mode = true;
|
||||
r.response_schema = Json::parse("{\"type\":\"object\",\"properties\":{}}");
|
||||
Json b = m.to_params(r).to_json();
|
||||
ASSERT_EQ(b.find("messages")->as_array()[0].find("role")->as_string(), "system");
|
||||
ASSERT_EQ(b.find("tool_choice")->as_string(), "REQUIRED");
|
||||
ASSERT_EQ(b.find("max_tokens")->as_int(), 50);
|
||||
ASSERT_EQ(b.find("p")->as_number(), 0.9);
|
||||
ASSERT_TRUE(b.find("response_format")->find("json_schema") != nullptr);
|
||||
r.tool_choice = "none";
|
||||
ASSERT_EQ(m.to_params(r).tool_choice, "NONE");
|
||||
r.tool_choice = "auto";
|
||||
ASSERT_EQ(m.to_params(r).tool_choice, "");
|
||||
r.tool_choice = "get_weather"; // a named tool cannot be forced
|
||||
ASSERT_THROW(m.to_params(r), ApiError);
|
||||
}
|
||||
|
||||
TEST(cohere_model, reasoning_effort_and_extra_thinking) {
|
||||
Rig rig;
|
||||
CohereChatModel m = make(rig);
|
||||
molo::llm::ChatRequest r;
|
||||
r.messages.push_back(molo::llm::Message::user("hi"));
|
||||
ASSERT_TRUE(m.to_params(r).thinking == Thinking::kDefault);
|
||||
r.reasoning_effort = "high";
|
||||
ASSERT_TRUE(m.to_params(r).thinking == Thinking::kEnabled);
|
||||
r.reasoning_effort = "none";
|
||||
ASSERT_TRUE(m.to_params(r).thinking == Thinking::kDisabled);
|
||||
r.reasoning_effort = "";
|
||||
r.extra = Json::parse("{\"thinking\":{\"token_budget\":512},\"priority\":3}");
|
||||
ChatParams p = m.to_params(r);
|
||||
ASSERT_TRUE(p.thinking == Thinking::kEnabled);
|
||||
ASSERT_EQ(*p.thinking_budget, 512L);
|
||||
ASSERT_EQ(p.to_json().find("priority")->as_int(), 3L);
|
||||
r.extra = Json::parse("{\"thinking\":{\"type\":\"sometimes\"}}");
|
||||
ASSERT_THROW(m.to_params(r), ApiError);
|
||||
}
|
||||
|
||||
TEST(cohere_model, messages_images_tool_calls_and_results_map_to_wire_roles) {
|
||||
Rig rig;
|
||||
CohereChatModel m = make(rig);
|
||||
molo::llm::ChatRequest r;
|
||||
molo::llm::Message user = molo::llm::Message::user("look");
|
||||
molo::llm::ImageData img;
|
||||
img.url = "https://example.com/a.png";
|
||||
user.parts.push_back(molo::llm::ContentPart::of_image(img));
|
||||
r.messages.push_back(user);
|
||||
molo::llm::Message asst;
|
||||
asst.role = molo::llm::Role::kAssistant;
|
||||
molo::llm::ContentPart think;
|
||||
think.reasoning = "hmm";
|
||||
asst.parts.push_back(think);
|
||||
molo::llm::ToolCall call;
|
||||
call.id = "c1";
|
||||
call.name = "f";
|
||||
call.arguments = Json::parse("{\"a\":1}");
|
||||
asst.parts.push_back(molo::llm::ContentPart::of_call(call));
|
||||
r.messages.push_back(asst);
|
||||
molo::llm::Message tool;
|
||||
tool.role = molo::llm::Role::kTool;
|
||||
tool.parts.push_back(molo::llm::ContentPart::of_result({"c1", "result", false}));
|
||||
r.messages.push_back(tool);
|
||||
Json b = m.to_params(r).to_json();
|
||||
const auto& msgs = b.find("messages")->as_array();
|
||||
ASSERT_EQ(msgs.size(), 3u);
|
||||
ASSERT_EQ(msgs[0].find("content")->as_array()[1].find("type")->as_string(), "image_url");
|
||||
ASSERT_EQ(msgs[1].find("tool_calls")->as_array()[0].find("function")->find("arguments")->as_string(), "{\"a\":1}");
|
||||
ASSERT_EQ(msgs[1].find("content")->as_array()[0].find("type")->as_string(), "thinking");
|
||||
ASSERT_EQ(msgs[2].find("role")->as_string(), "tool");
|
||||
ASSERT_EQ(msgs[2].find("tool_call_id")->as_string(), "c1");
|
||||
// image with raw bytes needs a mime type
|
||||
molo::llm::ChatRequest bad;
|
||||
molo::llm::Message u2 = molo::llm::Message::user("x");
|
||||
molo::llm::ImageData raw;
|
||||
raw.bytes = "abc";
|
||||
u2.parts.push_back(molo::llm::ContentPart::of_image(raw));
|
||||
bad.messages.push_back(u2);
|
||||
ASSERT_THROW(m.to_params(bad), ApiError);
|
||||
// a tool message with no result part
|
||||
molo::llm::ChatRequest bad2;
|
||||
molo::llm::Message t2;
|
||||
t2.role = molo::llm::Role::kTool;
|
||||
bad2.messages.push_back(t2);
|
||||
ASSERT_THROW(m.to_params(bad2), ApiError);
|
||||
}
|
||||
|
||||
TEST(cohere_model, generate_maps_the_documented_tool_example) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v2/chat", reply(kChatToolThinking));
|
||||
CohereChatModel m = make(rig);
|
||||
molo::llm::ChatRequest r;
|
||||
r.messages.push_back(molo::llm::Message::user("sales"));
|
||||
molo::llm::ChatResponse out = m.generate(r);
|
||||
ASSERT_EQ(out.finish_reason, "tool_calls");
|
||||
ASSERT_EQ(out.model, "command-a-03-2025");
|
||||
ASSERT_EQ(out.tool_calls().size(), 2u);
|
||||
ASSERT_EQ(out.tool_calls()[0].name, "query_daily_sales_report");
|
||||
ASSERT_EQ(out.tool_calls()[0].arguments.find("day")->as_string(), "2023-09-29");
|
||||
ASSERT_TRUE(out.message.parts[0].reasoning.find("sales summary") != std::string::npos);
|
||||
ASSERT_EQ(out.usage.input_tokens, 1032);
|
||||
ASSERT_EQ(out.usage.output_tokens, 124);
|
||||
ASSERT_EQ(out.usage.total_tokens, 1156);
|
||||
ASSERT_TRUE(out.raw.is_object());
|
||||
}
|
||||
|
||||
TEST(cohere_model, invalid_tool_arguments_are_kept_not_dropped) {
|
||||
ToolCallRecord bad;
|
||||
bad.id = "c";
|
||||
bad.name = "f";
|
||||
bad.arguments = "{not json";
|
||||
ChatResult r;
|
||||
r.tool_calls.push_back(bad);
|
||||
r.finish_reason = "TOOL_CALL";
|
||||
molo::llm::ChatResponse out = CohereChatModel::to_response(r);
|
||||
ASSERT_EQ(out.tool_calls()[0].arguments.find("_invalid_json")->as_string(), "{not json");
|
||||
}
|
||||
|
||||
TEST(cohere_model, stream_maps_text_tool_fragments_finish_and_usage) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v2/chat", sse(kStreamTools));
|
||||
CohereChatModel m = make(rig);
|
||||
molo::llm::ChatRequest r;
|
||||
r.messages.push_back(molo::llm::Message::user("sales"));
|
||||
std::string args, finish;
|
||||
std::string name, id;
|
||||
bool usage = false;
|
||||
m.stream(r, [&](const molo::llm::ChatChunk& c) {
|
||||
args += c.tool_args_delta;
|
||||
if (!c.tool_call_name.empty()) name = c.tool_call_name;
|
||||
if (!c.tool_call_id.empty()) id = c.tool_call_id;
|
||||
if (!c.finish_reason.empty()) finish = c.finish_reason;
|
||||
if (c.usage) usage = true;
|
||||
return true;
|
||||
});
|
||||
ASSERT_EQ(finish, "tool_calls");
|
||||
ASSERT_TRUE(usage);
|
||||
ASSERT_FALSE(name.empty());
|
||||
ASSERT_FALSE(id.empty());
|
||||
ASSERT_TRUE(has(args, "day"));
|
||||
}
|
||||
|
||||
TEST(cohere_model, finish_reasons_map_to_the_neutral_words) {
|
||||
ASSERT_EQ(CohereChatModel::neutral_finish("COMPLETE"), "stop");
|
||||
ASSERT_EQ(CohereChatModel::neutral_finish("STOP_SEQUENCE"), "stop");
|
||||
ASSERT_EQ(CohereChatModel::neutral_finish("MAX_TOKENS"), "length");
|
||||
ASSERT_EQ(CohereChatModel::neutral_finish("TOOL_CALL"), "tool_calls");
|
||||
ASSERT_EQ(CohereChatModel::neutral_finish("ERROR"), "error");
|
||||
ASSERT_EQ(CohereChatModel::neutral_finish("TIMEOUT"), "timeout");
|
||||
ASSERT_EQ(CohereChatModel::neutral_finish("SOMETHING_NEW"), "SOMETHING_NEW");
|
||||
}
|
||||
|
||||
TEST(cohere_model, works_through_the_neutral_pointer) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v2/chat", reply(kChatBasic));
|
||||
std::shared_ptr<molo::llm::ChatModel> model = std::make_shared<CohereChatModel>(std::make_shared<Chat>(rig.client()));
|
||||
molo::llm::ChatRequest r;
|
||||
r.messages.push_back(molo::llm::Message::user("Tell me about LLMs"));
|
||||
ASSERT_TRUE(has(model->generate(r).text(), "Large Language Models"));
|
||||
}
|
||||
+498
@@ -0,0 +1,498 @@
|
||||
// Embed, rerank, classify, tokenize, legacy calls, account, datasets, batches,
|
||||
// embed jobs, connectors, fine-tuning, parse, transcription. Documented
|
||||
// examples are verbatim (fixtures.h); documents with no published example are
|
||||
// minimal SHAPE fixtures built from the OpenAPI schema and labelled so.
|
||||
#include "support.h"
|
||||
#include "vendors/cohere/inference.h"
|
||||
#include "vendors/cohere/resources.h"
|
||||
|
||||
using namespace molo::cohere;
|
||||
using namespace cohere_test;
|
||||
using molo::llm::ApiError;
|
||||
|
||||
// ---- inference -------------------------------------------------------------
|
||||
|
||||
TEST(cohere_embed, v2_request_body_and_documented_response) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v2/embed", reply(kEmbedV2));
|
||||
Embeddings api(rig.client());
|
||||
EmbedParams p;
|
||||
p.texts = {"hello", "world"};
|
||||
p.embedding_types = {"float", "int8"};
|
||||
p.truncate = "END";
|
||||
p.output_dimension = 1024;
|
||||
EmbedResult r = api.embed(p);
|
||||
ASSERT_TRUE(!r.id.empty());
|
||||
auto floats = r.floats();
|
||||
ASSERT_TRUE(!floats.empty());
|
||||
ASSERT_TRUE(floats[0].size() > 100);
|
||||
auto s = rig.mock->seen()[0];
|
||||
ASSERT_TRUE(has(s.body, "\"model\":\"embed-v4.0\""));
|
||||
ASSERT_TRUE(has(s.body, "\"input_type\":\"search_document\""));
|
||||
ASSERT_TRUE(has(s.body, "\"embedding_types\":[\"float\",\"int8\"]"));
|
||||
ASSERT_TRUE(has(s.body, "\"output_dimension\":1024"));
|
||||
}
|
||||
|
||||
TEST(cohere_embed, v1_floats_array_and_input_rules) {
|
||||
Rig rig;
|
||||
// SHAPE: v1 embed answers embeddings as an array of float rows (schema: embeddings_floats).
|
||||
rig.mock->expect_response(Method::kPost, "/v1/embed",
|
||||
reply("{\"id\":\"e1\",\"response_type\":\"embeddings_floats\",\"texts\":[\"a\"],\"embeddings\":[[0.5,0.25]],\"meta\":{\"billed_units\":{\"input_tokens\":3}}}"));
|
||||
Embeddings api(rig.client());
|
||||
EmbedParams p;
|
||||
p.texts = {"a"};
|
||||
p.model = "embed-english-v3.0";
|
||||
EmbedResult r = api.embed_v1(p);
|
||||
ASSERT_EQ(r.floats().size(), 1u);
|
||||
ASSERT_EQ(r.floats()[0][1], 0.25);
|
||||
ASSERT_EQ(r.usage.billed_input_tokens, 3);
|
||||
EmbedParams mixed;
|
||||
mixed.inputs.push_back(Json::parse("{\"content\":[{\"type\":\"text\",\"text\":\"x\"}]}"));
|
||||
ASSERT_THROW(api.embed_v1(mixed), ApiError); // v1 takes texts and images only
|
||||
EmbedParams none;
|
||||
ASSERT_THROW(api.embed(none), ApiError);
|
||||
EmbedParams many;
|
||||
many.texts.assign(97, "x");
|
||||
ASSERT_THROW(api.embed(many), ApiError);
|
||||
EmbedParams bad_type;
|
||||
bad_type.texts = {"x"};
|
||||
bad_type.input_type = "other";
|
||||
ASSERT_THROW(api.embed(bad_type), ApiError);
|
||||
bad_type.input_type = "search_query";
|
||||
bad_type.embedding_types = {"float16"};
|
||||
ASSERT_THROW(api.embed(bad_type), ApiError);
|
||||
EmbedParams empty_text;
|
||||
empty_text.texts = {""};
|
||||
ASSERT_THROW(api.embed(empty_text), ApiError);
|
||||
EmbedParams bad_img;
|
||||
bad_img.images = {"file:///etc/passwd"};
|
||||
ASSERT_THROW(api.embed(bad_img), ApiError);
|
||||
ASSERT_EQ(rig.mock->send_count(), 1u);
|
||||
}
|
||||
|
||||
TEST(cohere_rerank, documented_example_and_span_options) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v2/rerank", reply(kRerankV2));
|
||||
Rerank api(rig.client());
|
||||
RerankParams p;
|
||||
p.model = "rerank-v5.0-pro";
|
||||
p.query = "What is the capital of the United States?";
|
||||
p.documents = {"a", "b", "c", "d", "e"};
|
||||
p.top_n = 3;
|
||||
p.relevant_spans = "enabled";
|
||||
p.spans_threshold = 0.1;
|
||||
p.max_spans = 3;
|
||||
RerankResult r = api.rerank(p);
|
||||
ASSERT_EQ(r.hits.size(), 3u);
|
||||
ASSERT_EQ(r.hits[0].index, 2);
|
||||
ASSERT_TRUE(r.hits[0].score > 0.84 && r.hits[0].score < 0.85);
|
||||
ASSERT_TRUE(r.hits[0].spans.is_array());
|
||||
ASSERT_EQ(r.usage.billed_input_tokens, 192);
|
||||
ASSERT_TRUE(has(rig.mock->seen()[0].body, "\"relevant_spans\":{\"max_spans\":3,\"mode\":\"enabled\",\"threshold\":0.1}"));
|
||||
RerankParams bad = p;
|
||||
bad.documents.clear();
|
||||
ASSERT_THROW(api.rerank(bad), ApiError);
|
||||
bad = p;
|
||||
bad.query = "";
|
||||
ASSERT_THROW(api.rerank(bad), ApiError);
|
||||
bad = p;
|
||||
bad.relevant_spans = "disabled"; // options need enabled
|
||||
ASSERT_THROW(api.rerank(bad), ApiError);
|
||||
bad = p;
|
||||
bad.top_n = 0;
|
||||
ASSERT_THROW(api.rerank(bad), ApiError);
|
||||
bad = p;
|
||||
bad.documents.assign(1001, "x");
|
||||
ASSERT_THROW(api.rerank(bad), ApiError);
|
||||
}
|
||||
|
||||
TEST(cohere_rerank, v1_passthrough_checks_fields) {
|
||||
Rig rig;
|
||||
// SHAPE: v1 rerank result (schema rerank.results: index, relevance_score).
|
||||
rig.mock->expect_response(Method::kPost, "/v1/rerank", reply("{\"id\":\"r\",\"results\":[{\"index\":0,\"relevance_score\":0.9}]}"));
|
||||
Rerank api(rig.client());
|
||||
Json out = api.rerank_v1(Json::parse("{\"model\":\"rerank-v3.5\",\"query\":\"q\",\"documents\":[\"a\"],\"return_documents\":true}"));
|
||||
ASSERT_EQ(out.find("results")->as_array().size(), 1u);
|
||||
ASSERT_THROW(api.rerank_v1(Json::parse("{\"query\":\"q\",\"documents\":[]}")), ApiError);
|
||||
ASSERT_THROW(api.rerank_v1(Json::parse("{\"query\":\"q\",\"documents\":[\"a\"],\"extra\":1}")), ApiError);
|
||||
}
|
||||
|
||||
TEST(cohere_classify, documented_example_and_rules) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v1/classify", reply(kClassify));
|
||||
Classify api(rig.client());
|
||||
ClassifyParams p;
|
||||
p.inputs = {"Confirm your email address", "hey i need u to send some $"};
|
||||
p.model = "YOUR-FINE-TUNED-MODEL-ID";
|
||||
ClassifyResult r = api.classify(p);
|
||||
ASSERT_EQ(r.items.size(), 2u);
|
||||
ASSERT_EQ(r.items[0].prediction, "Not spam");
|
||||
ASSERT_EQ(r.items[1].prediction, "Spam");
|
||||
ASSERT_TRUE(r.items[1].confidence > 0.99);
|
||||
ASSERT_EQ(r.items[0].classification_type, "single-label");
|
||||
ASSERT_TRUE(r.items[0].labels.find("Spam") != nullptr);
|
||||
ClassifyParams bad;
|
||||
bad.inputs = {"x"};
|
||||
ASSERT_THROW(api.classify(bad), ApiError); // no model and fewer than 2 examples
|
||||
bad.examples = {{"a", "A"}, {"b", ""}};
|
||||
ASSERT_THROW(api.classify(bad), ApiError);
|
||||
ClassifyParams none;
|
||||
none.model = "m";
|
||||
ASSERT_THROW(api.classify(none), ApiError);
|
||||
ASSERT_EQ(rig.mock->send_count(), 1u);
|
||||
}
|
||||
|
||||
TEST(cohere_tokenizer, documented_examples_and_caps) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v1/tokenize", reply(kTokenize));
|
||||
rig.mock->expect_response(Method::kPost, "/v1/detokenize", reply(kDetokenize));
|
||||
Tokenizer api(rig.client());
|
||||
TokenizeResult t = api.tokenize("command", "tokenize me! :D");
|
||||
ASSERT_EQ(t.tokens.size(), 6u);
|
||||
ASSERT_EQ(t.tokens[0], 10002L);
|
||||
ASSERT_EQ(t.token_strings[2], " me");
|
||||
ASSERT_EQ(api.detokenize("command", t.tokens), "tokenize me! :D");
|
||||
ASSERT_TRUE(has(rig.mock->seen()[1].body, "\"tokens\":[10002,2261,2012,8,2792,43]"));
|
||||
ASSERT_THROW(api.tokenize("command", ""), ApiError);
|
||||
ASSERT_THROW(api.tokenize("command", std::string(65537, 'a')), ApiError);
|
||||
ASSERT_THROW(api.detokenize("command", {}), ApiError);
|
||||
ASSERT_THROW(api.detokenize("command", std::vector<long>(65537, 1)), ApiError);
|
||||
ASSERT_THROW(api.detokenize("command", {-1}), ApiError);
|
||||
ASSERT_THROW(api.tokenize("bad model", "x"), ApiError);
|
||||
ASSERT_EQ(rig.mock->send_count(), 2u);
|
||||
}
|
||||
|
||||
TEST(cohere_legacy, summarize_and_generate_validate_before_sending) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v1/summarize", reply(kSummarize));
|
||||
rig.mock->expect_response(Method::kPost, "/v1/generate", reply("{\"id\":\"g\",\"generations\":[{\"id\":\"1\",\"text\":\"x\"}]}")); // SHAPE
|
||||
Legacy api(rig.client());
|
||||
Json s = api.summarize(Json::parse("{\"text\":\"a long text\",\"length\":\"short\"}"));
|
||||
ASSERT_TRUE(s.find("summary") != nullptr);
|
||||
ASSERT_TRUE(api.generate(Json::parse("{\"prompt\":\"hi\",\"max_tokens\":5}")).find("generations") != nullptr);
|
||||
ASSERT_THROW(api.summarize(Json::parse("{\"length\":\"short\"}")), ApiError);
|
||||
ASSERT_THROW(api.generate(Json::parse("{\"prompt\":\"x\",\"stream\":true}")), ApiError);
|
||||
ASSERT_THROW(api.generate(Json::parse("{\"prompt\":\"x\",\"n\":2}")), ApiError);
|
||||
ASSERT_EQ(rig.mock->send_count(), 2u);
|
||||
}
|
||||
|
||||
// ---- account ---------------------------------------------------------------
|
||||
|
||||
TEST(cohere_account, check_api_key_posts_without_a_body) {
|
||||
Rig rig;
|
||||
// PROBE: an invalid key answered HTTP 200 {"valid":false} on 2026-10-25.
|
||||
rig.mock->expect_response(Method::kPost, "/v1/check-api-key", reply("{\"valid\":false}"));
|
||||
ApiKeyCheck c = Account(rig.client()).check_api_key();
|
||||
ASSERT_FALSE(c.valid);
|
||||
ASSERT_EQ(rig.mock->seen()[0].body, "");
|
||||
}
|
||||
|
||||
TEST(cohere_account, models_list_filters_and_walk_reports_truncation) {
|
||||
Rig rig;
|
||||
// SHAPE: ListModelsResponse / GetModelResponse built from the schema (no published example).
|
||||
const std::string page1 =
|
||||
"{\"models\":[{\"name\":\"command-a-03-2025\",\"endpoints\":[\"chat\"],\"finetuned\":false,\"context_length\":256000,"
|
||||
"\"features\":[\"tools\"],\"is_deprecated\":false}],\"next_page_token\":\"tok\"}";
|
||||
rig.mock->expect_response(Method::kGet, "/v1/models", reply(page1));
|
||||
Account api(rig.client());
|
||||
ModelList l = api.models("chat", true, 50);
|
||||
ASSERT_EQ(l.models.size(), 1u);
|
||||
ASSERT_TRUE(l.find("command-a-03-2025")->supports("chat"));
|
||||
ASSERT_EQ(l.page.next_page_token, "tok");
|
||||
ASSERT_EQ(rig.mock->seen()[0].target, "/v1/models?endpoint=chat&default_only=true&page_size=50");
|
||||
ASSERT_THROW(api.models("", true), ApiError); // default_only needs endpoint
|
||||
ASSERT_THROW(api.models("nonsense"), ApiError);
|
||||
ASSERT_THROW(api.models("", false, 0), ApiError);
|
||||
ASSERT_THROW(api.models("", false, 1001), ApiError);
|
||||
|
||||
// The walk follows next_page_token and stops at the page cap, saying so.
|
||||
Rig walk;
|
||||
MockExpectation e;
|
||||
e.method = Method::kGet;
|
||||
e.path = "/v1/models";
|
||||
e.response = reply(page1);
|
||||
e.times = 100;
|
||||
walk.mock->expect(e);
|
||||
ModelList all = Account(walk.client()).all_models();
|
||||
ASSERT_EQ(walk.mock->send_count(), 20u);
|
||||
ASSERT_TRUE(all.page.truncated);
|
||||
ASSERT_EQ(all.models.size(), 20u);
|
||||
}
|
||||
|
||||
TEST(cohere_account, get_model_validates_the_name) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kGet, "/v1/models/command-a-03-2025",
|
||||
reply("{\"name\":\"command-a-03-2025\",\"endpoints\":[\"chat\",\"generate\"],\"context_length\":256000,\"default_endpoints\":[\"chat\"]}"));
|
||||
ModelInfo m = Account(rig.client()).model("command-a-03-2025");
|
||||
ASSERT_EQ(m.context_length, 256000.0);
|
||||
ASSERT_TRUE(m.supports("generate"));
|
||||
ASSERT_THROW(Account(rig.client()).model("../x"), ApiError);
|
||||
ASSERT_THROW(Account(rig.client()).model(""), ApiError);
|
||||
}
|
||||
|
||||
// ---- datasets, batches, embed jobs -------------------------------------------
|
||||
|
||||
TEST(cohere_datasets, upload_is_multipart_with_query_and_validated) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v1/datasets", reply("{\"id\":\"ds-1\"}")); // SHAPE: create-dataset
|
||||
Datasets api(rig.client());
|
||||
DatasetUpload u;
|
||||
u.name = "my data";
|
||||
u.type = "embed-input";
|
||||
u.filename = "d.jsonl";
|
||||
u.data = "{\"text\":\"a\"}\n";
|
||||
u.keep_fields = {"a", "b"};
|
||||
u.skip_malformed_input = true;
|
||||
ASSERT_EQ(api.create(u), "ds-1");
|
||||
auto s = rig.mock->seen()[0];
|
||||
ASSERT_TRUE(has(s.target, "name=my%20data"));
|
||||
ASSERT_TRUE(has(s.target, "type=embed-input"));
|
||||
ASSERT_TRUE(has(s.target, "keep_fields=a&keep_fields=b"));
|
||||
ASSERT_TRUE(has(s.target, "skip_malformed_input=true"));
|
||||
ASSERT_TRUE(has(s.headers.get_or("Content-Type", ""), "multipart/form-data"));
|
||||
ASSERT_TRUE(has(s.body, "name=\"data\"; filename=\"d.jsonl\""));
|
||||
DatasetUpload bad = u;
|
||||
bad.type = "nope";
|
||||
ASSERT_THROW(api.create(bad), ApiError);
|
||||
bad = u;
|
||||
bad.data.clear();
|
||||
ASSERT_THROW(api.create(bad), ApiError);
|
||||
bad = u;
|
||||
bad.filename = "a/b";
|
||||
ASSERT_THROW(api.create(bad), ApiError);
|
||||
bad = u;
|
||||
bad.eval_data = "x"; // needs eval_filename
|
||||
ASSERT_THROW(api.create(bad), ApiError);
|
||||
bad = u;
|
||||
bad.name = "";
|
||||
ASSERT_THROW(api.create(bad), ApiError);
|
||||
ASSERT_EQ(rig.mock->send_count(), 1u);
|
||||
}
|
||||
|
||||
TEST(cohere_datasets, list_get_usage_remove) {
|
||||
Rig rig;
|
||||
// SHAPE documents from the Dataset schema.
|
||||
const std::string ds =
|
||||
"{\"id\":\"ds-1\",\"name\":\"n\",\"created_at\":\"2026-01-01T00:00:00Z\",\"updated_at\":\"2026-01-01T00:00:00Z\","
|
||||
"\"dataset_type\":\"embed-input\",\"validation_status\":\"validated\",\"dataset_parts\":[{\"id\":\"p1\",\"name\":\"d.jsonl\",\"num_rows\":3}]}";
|
||||
rig.mock->expect_response(Method::kGet, "/v1/datasets", reply("{\"datasets\":[" + ds + "]}"));
|
||||
rig.mock->expect_response(Method::kGet, "/v1/datasets/ds-1", reply("{\"dataset\":" + ds + "}"));
|
||||
rig.mock->expect_response(Method::kGet, "/v1/datasets/usage", reply("{\"organization_usage\":\"1024\"}"));
|
||||
rig.mock->expect_response(Method::kDelete, "/v1/datasets/ds-1", reply("{}"));
|
||||
Datasets api(rig.client());
|
||||
DatasetFilter f;
|
||||
f.dataset_type = "embed-input";
|
||||
f.validation_status = "validated";
|
||||
f.limit = 10;
|
||||
auto list = api.list(f);
|
||||
ASSERT_EQ(list.size(), 1u);
|
||||
ASSERT_TRUE(list[0].validated());
|
||||
ASSERT_EQ(list[0].parts[0].num_rows, 3L);
|
||||
ASSERT_TRUE(has(rig.mock->seen()[0].target, "datasetType=embed-input"));
|
||||
ASSERT_TRUE(has(rig.mock->seen()[0].target, "validationStatus=validated"));
|
||||
ASSERT_EQ(api.get("ds-1").name, "n");
|
||||
ASSERT_EQ(api.usage().as_string(), "1024");
|
||||
api.remove("ds-1");
|
||||
ASSERT_EQ(rig.mock->seen()[3].method, "DELETE");
|
||||
DatasetFilter bad;
|
||||
bad.limit = 0;
|
||||
ASSERT_THROW(api.list(bad), ApiError);
|
||||
bad = DatasetFilter();
|
||||
bad.validation_status = "weird";
|
||||
ASSERT_THROW(api.list(bad), ApiError);
|
||||
ASSERT_THROW(api.get("a/b"), ApiError);
|
||||
ASSERT_THROW(api.remove(".."), ApiError);
|
||||
}
|
||||
|
||||
TEST(cohere_datasets, await_validation_polls_with_a_caller_supplied_wait_and_a_cap) {
|
||||
Rig rig;
|
||||
MockExpectation e;
|
||||
e.method = Method::kGet;
|
||||
e.path = "/v1/datasets/ds-1";
|
||||
e.response = reply("{\"dataset\":{\"id\":\"ds-1\",\"name\":\"n\",\"validation_status\":\"processing\"}}");
|
||||
e.times = 10;
|
||||
rig.mock->expect(e);
|
||||
int waits = 0;
|
||||
Dataset d = Datasets(rig.client()).await_validation("ds-1", 3, [&] { ++waits; });
|
||||
ASSERT_EQ(d.validation_status, "processing");
|
||||
ASSERT_EQ(rig.mock->send_count(), 3u);
|
||||
ASSERT_EQ(waits, 3);
|
||||
ASSERT_THROW(Datasets(rig.client()).await_validation("ds-1", 0, nullptr), ApiError);
|
||||
ASSERT_THROW(Datasets(rig.client()).await_validation("ds-1", 61, nullptr), ApiError);
|
||||
}
|
||||
|
||||
TEST(cohere_batches, create_get_list_cancel) {
|
||||
Rig rig;
|
||||
// SHAPE documents from the Batch schema.
|
||||
const std::string b =
|
||||
"{\"id\":\"b1\",\"name\":\"nightly\",\"status\":\"BATCH_STATUS_IN_PROGRESS\",\"input_dataset_id\":\"ds-1\",\"model\":\"command-a-03-2025\",\"num_records\":10,\"input_tokens\":\"42\"}";
|
||||
rig.mock->expect_response(Method::kPost, "/v2/batches", reply("{\"batch\":" + b + "}"));
|
||||
rig.mock->expect_response(Method::kGet, "/v2/batches/b1", reply("{\"batch\":" + b + "}"));
|
||||
rig.mock->expect_response(Method::kGet, "/v2/batches", reply("{\"batches\":[" + b + "],\"next_page_token\":\"n\"}"));
|
||||
rig.mock->expect_response(Method::kPost, "/v2/batches/b1:cancel", reply("{}"));
|
||||
Batches api(rig.client());
|
||||
Batch made = api.create("nightly", "ds-1", "command-a-03-2025");
|
||||
ASSERT_EQ(made.id, "b1");
|
||||
ASSERT_FALSE(made.terminal());
|
||||
ASSERT_EQ(made.input_tokens, "42");
|
||||
ASSERT_TRUE(has(rig.mock->seen()[0].body, "\"input_dataset_id\":\"ds-1\""));
|
||||
ASSERT_EQ(api.get("b1").num_records, 10L);
|
||||
BatchList l = api.list(20, "", "updated_at");
|
||||
ASSERT_EQ(l.batches.size(), 1u);
|
||||
ASSERT_EQ(l.page.next_page_token, "n");
|
||||
ASSERT_EQ(rig.mock->seen()[2].target, "/v2/batches?page_size=20&order_by=updated_at");
|
||||
api.cancel("b1");
|
||||
ASSERT_EQ(rig.mock->seen()[3].method, "POST");
|
||||
ASSERT_EQ(rig.mock->seen()[3].body, "");
|
||||
ASSERT_THROW(api.create("", "ds-1", "m"), ApiError);
|
||||
ASSERT_THROW(api.create("n", "a/b", "m"), ApiError);
|
||||
ASSERT_THROW(api.list(20, "", "name"), ApiError);
|
||||
ASSERT_THROW(api.cancel("x?y"), ApiError);
|
||||
Batch done;
|
||||
done.status = "BATCH_STATUS_COMPLETED";
|
||||
ASSERT_TRUE(done.terminal());
|
||||
}
|
||||
|
||||
TEST(cohere_embed_jobs, create_list_get_cancel) {
|
||||
Rig rig;
|
||||
// SHAPE documents from CreateEmbedJobResponse / EmbedJob.
|
||||
rig.mock->expect_response(Method::kPost, "/v1/embed-jobs", reply("{\"job_id\":\"j1\"}"));
|
||||
rig.mock->expect_response(Method::kGet, "/v1/embed-jobs", reply("{\"embed_jobs\":[{\"job_id\":\"j1\",\"status\":\"processing\",\"model\":\"embed-v4.0\"}]}"));
|
||||
rig.mock->expect_response(Method::kGet, "/v1/embed-jobs/j1", reply("{\"job_id\":\"j1\",\"status\":\"complete\",\"output_dataset_id\":\"o1\"}"));
|
||||
rig.mock->expect_response(Method::kPost, "/v1/embed-jobs/j1/cancel", reply("{}"));
|
||||
EmbedJobs api(rig.client());
|
||||
EmbedJobParams p;
|
||||
p.dataset_id = "ds-1";
|
||||
p.name = "job";
|
||||
p.embedding_types = {"float"};
|
||||
p.truncate = "END";
|
||||
ASSERT_EQ(api.create(p), "j1");
|
||||
ASSERT_TRUE(has(rig.mock->seen()[0].body, "\"dataset_id\":\"ds-1\""));
|
||||
ASSERT_EQ(api.list().size(), 1u);
|
||||
EmbedJob j = api.get("j1");
|
||||
ASSERT_TRUE(j.terminal());
|
||||
ASSERT_EQ(j.output_dataset_id, "o1");
|
||||
api.cancel("j1");
|
||||
EmbedJobParams bad = p;
|
||||
bad.dataset_id = "";
|
||||
ASSERT_THROW(api.create(bad), ApiError);
|
||||
bad = p;
|
||||
bad.truncate = "NONE"; // jobs accept START or END only
|
||||
ASSERT_THROW(api.create(bad), ApiError);
|
||||
bad = p;
|
||||
bad.input_type = "x";
|
||||
ASSERT_THROW(api.create(bad), ApiError);
|
||||
ASSERT_THROW(api.get("../x"), ApiError);
|
||||
}
|
||||
|
||||
// ---- connectors and fine-tuning ---------------------------------------------
|
||||
|
||||
TEST(cohere_connectors, crud_and_oauth_authorize) {
|
||||
Rig rig;
|
||||
// SHAPE documents from the Connector schema.
|
||||
const std::string c = "{\"connector\":{\"id\":\"c1\",\"name\":\"wiki\",\"url\":\"https://example.com/search\",\"active\":true,\"excludes\":[\"a\"]}}";
|
||||
rig.mock->expect_response(Method::kPost, "/v1/connectors", reply(c));
|
||||
rig.mock->expect_response(Method::kGet, "/v1/connectors/c1", reply(c));
|
||||
rig.mock->expect_response(Method::kPatch, "/v1/connectors/c1", reply(c));
|
||||
rig.mock->expect_response(Method::kGet, "/v1/connectors", reply("{\"connectors\":[" + c.substr(13, c.size() - 14) + "],\"total_count\":1}"));
|
||||
rig.mock->expect_response(Method::kDelete, "/v1/connectors/c1", reply("{}"));
|
||||
rig.mock->expect_response(Method::kPost, "/v1/connectors/c1/oauth/authorize", reply("{\"redirect_url\":\"https://auth.example.com/x\"}"));
|
||||
Connectors api(rig.client());
|
||||
ConnectorParams p;
|
||||
p.name = "wiki";
|
||||
p.url = "https://example.com/search";
|
||||
p.excludes = {"a"};
|
||||
p.active = true;
|
||||
Connector made = api.create(p);
|
||||
ASSERT_EQ(made.id, "c1");
|
||||
ASSERT_TRUE(made.active);
|
||||
ASSERT_TRUE(has(rig.mock->seen()[0].body, "\"url\":\"https://example.com/search\""));
|
||||
ASSERT_EQ(api.get("c1").name, "wiki");
|
||||
ConnectorParams patch;
|
||||
patch.active = false;
|
||||
api.update("c1", patch);
|
||||
ASSERT_EQ(rig.mock->seen()[2].body, "{\"active\":false}");
|
||||
ASSERT_EQ(api.list(10).size(), 1u);
|
||||
api.remove("c1");
|
||||
ASSERT_EQ(api.oauth_authorize("c1", "https://app.example.com/done"), "https://auth.example.com/x");
|
||||
ASSERT_TRUE(has(rig.mock->seen()[5].target, "after_token_redirect=https%3A%2F%2Fapp.example.com%2Fdone"));
|
||||
ConnectorParams bad;
|
||||
ASSERT_THROW(api.create(bad), ApiError); // needs name and url
|
||||
bad.name = "n";
|
||||
bad.url = "ftp://x";
|
||||
ASSERT_THROW(api.create(bad), ApiError);
|
||||
ASSERT_THROW(api.update("c1", ConnectorParams()), ApiError); // nothing to send
|
||||
ConnectorParams oauth;
|
||||
oauth.name = "n";
|
||||
oauth.url = "https://x.example.com";
|
||||
oauth.oauth = Json::parse("{\"client_id\":\"i\"}");
|
||||
ASSERT_THROW(api.create(oauth), ApiError); // authorize_url and token_url missing
|
||||
ASSERT_THROW(api.list(0), ApiError);
|
||||
}
|
||||
|
||||
TEST(cohere_finetuning, lifecycle_calls_and_settings_rules) {
|
||||
Rig rig;
|
||||
// SHAPE documents from the FinetunedModel schema.
|
||||
const std::string m = "{\"finetuned_model\":{\"id\":\"ft1\",\"name\":\"mine\",\"status\":\"STATUS_READY\",\"settings\":{\"dataset_id\":\"ds-1\"}}}";
|
||||
rig.mock->expect_response(Method::kPost, "/v1/finetuning/finetuned-models", reply(m));
|
||||
rig.mock->expect_response(Method::kGet, "/v1/finetuning/finetuned-models/ft1", reply(m));
|
||||
rig.mock->expect_response(Method::kPatch, "/v1/finetuning/finetuned-models/ft1", reply(m));
|
||||
rig.mock->expect_response(Method::kGet, "/v1/finetuning/finetuned-models",
|
||||
reply("{\"finetuned_models\":[{\"id\":\"ft1\",\"name\":\"mine\"}],\"next_page_token\":\"t\",\"total_size\":7}"));
|
||||
rig.mock->expect_response(Method::kGet, "/v1/finetuning/finetuned-models/ft1/events", reply("{\"events\":[{\"status\":\"STATUS_QUEUED\"}]}"));
|
||||
rig.mock->expect_response(Method::kGet, "/v1/finetuning/finetuned-models/ft1/training-step-metrics", reply("{\"step_metrics\":[]}"));
|
||||
rig.mock->expect_response(Method::kDelete, "/v1/finetuning/finetuned-models/ft1", reply("{}"));
|
||||
FineTuning api(rig.client());
|
||||
Json settings = Json::parse("{\"base_model\":{\"base_type\":\"BASE_TYPE_CHAT\"},\"dataset_id\":\"ds-1\"}");
|
||||
FinetunedModel made = api.create("mine", settings);
|
||||
ASSERT_TRUE(made.ready());
|
||||
ASSERT_EQ(made.id, "ft1");
|
||||
ASSERT_TRUE(has(rig.mock->seen()[0].body, "\"base_type\":\"BASE_TYPE_CHAT\""));
|
||||
ASSERT_EQ(api.get("ft1").name, "mine");
|
||||
api.update("ft1", "renamed", Json());
|
||||
ASSERT_EQ(rig.mock->seen()[2].body, "{\"name\":\"renamed\"}");
|
||||
auto page = api.list(5);
|
||||
ASSERT_EQ(page.models.size(), 1u);
|
||||
ASSERT_EQ(page.page.total, 7L);
|
||||
ASSERT_EQ(page.page.next_page_token, "t");
|
||||
ASSERT_TRUE(api.events("ft1").find("events") != nullptr);
|
||||
ASSERT_TRUE(api.step_metrics("ft1", 10).find("step_metrics") != nullptr);
|
||||
api.remove("ft1");
|
||||
ASSERT_THROW(api.create("", settings), ApiError);
|
||||
ASSERT_THROW(api.create("n", Json::parse("{\"dataset_id\":\"d\"}")), ApiError); // no base_model
|
||||
ASSERT_THROW(api.create("n", Json::parse("{\"base_model\":{\"base_type\":\"x\"}}")), ApiError); // no dataset_id
|
||||
ASSERT_THROW(api.update("ft1", "", Json()), ApiError);
|
||||
ASSERT_THROW(api.events("a/b"), ApiError);
|
||||
}
|
||||
|
||||
// ---- parse and transcription -------------------------------------------------
|
||||
|
||||
TEST(cohere_documents, parse_and_transcribe_validate_and_send) {
|
||||
Rig rig;
|
||||
rig.mock->expect_response(Method::kPost, "/v2/parse", reply("{\"id\":\"p1\",\"pages\":[]}")); // SHAPE: ParseResponse
|
||||
rig.mock->expect_response(Method::kPost, "/v2/audio/transcriptions", reply("{\"text\":\"hello\"}")); // SHAPE
|
||||
Documents api(rig.client());
|
||||
Json out = api.parse("some-parse-model", "https://example.com/page.png", "markdown");
|
||||
ASSERT_EQ(out.find("id")->as_string(), "p1");
|
||||
ASSERT_TRUE(has(rig.mock->seen()[0].body, "\"document\":{\"image_url\":\"https://example.com/page.png\",\"type\":\"image_url\"}"));
|
||||
ASSERT_EQ(api.transcribe("m", "en", "a.wav", "audio/wav", "RIFFxxxx", 0.0), "hello");
|
||||
auto s = rig.mock->seen()[1];
|
||||
ASSERT_TRUE(has(s.headers.get_or("Content-Type", ""), "multipart/form-data"));
|
||||
ASSERT_TRUE(has(s.body, "name=\"language\""));
|
||||
ASSERT_TRUE(has(s.body, "filename=\"a.wav\""));
|
||||
ASSERT_THROW(api.parse("m", "ftp://x"), ApiError);
|
||||
ASSERT_THROW(api.parse("m", "https://x.example.com/a.png", "html"), ApiError);
|
||||
ASSERT_THROW(api.transcribe("m", "", "a.wav", "audio/wav", "x"), ApiError);
|
||||
ASSERT_THROW(api.transcribe("m", "en", "a.wav", "audio/wav", ""), ApiError);
|
||||
ASSERT_THROW(api.transcribe("m", "en", "a/b.wav", "audio/wav", "x"), ApiError);
|
||||
ASSERT_THROW(api.transcribe("m", "en", "a.wav", "audio/wav", "x", 3.0), ApiError);
|
||||
ASSERT_EQ(rig.mock->send_count(), 2u);
|
||||
}
|
||||
|
||||
TEST(cohere_resources, nothing_is_sent_without_a_key) {
|
||||
Rig rig("");
|
||||
ASSERT_THROW(Account(rig.client()).check_api_key(), molo::llm::NotConfiguredError);
|
||||
ASSERT_THROW(Datasets(rig.client()).list(), molo::llm::NotConfiguredError);
|
||||
ASSERT_THROW(Batches(rig.client()).cancel("b1"), molo::llm::NotConfiguredError);
|
||||
ASSERT_EQ(rig.mock->send_count(), 0u);
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
// Opt-in live checks. MOLO_LIVE_NET=1 enables the network; COHERE_API_KEY (via
|
||||
// llm::Config) enables the read-only calls plus ONE tiny chat; embed and rerank
|
||||
// additionally need MOLO_LIVE_PAID=1. Without them each test prints a loud SKIP.
|
||||
// Nothing is created, updated or deleted.
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#include "clients/transports/http_transport.h"
|
||||
#include "support.h"
|
||||
#include "vendors/cohere/chat.h"
|
||||
#include "vendors/cohere/inference.h"
|
||||
#include "vendors/cohere/resources.h"
|
||||
|
||||
using namespace molo::cohere;
|
||||
using molo::llm::ApiError;
|
||||
|
||||
namespace {
|
||||
bool net() { return std::getenv("MOLO_LIVE_NET") != nullptr; }
|
||||
bool paid() { return std::getenv("MOLO_LIVE_PAID") != nullptr; }
|
||||
|
||||
std::shared_ptr<molo::llm::ApiClient> invalid_key_client() {
|
||||
return std::make_shared<molo::llm::ApiClient>(std::make_unique<molo::clients::transports::HttpTransport>(),
|
||||
Platform::config(), "invalid-molo-probe");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// No key needed. 2026-10-25 observations: an invalid key on GET /v1/models answers 401 with
|
||||
// {"id","message"}; POST /v1/check-api-key with an invalid key answers 200 {"valid":false}.
|
||||
TEST(cohere_live, invalid_key_probes) {
|
||||
if (!net()) {
|
||||
std::cout << "SKIP cohere_live.invalid_key_probes (set MOLO_LIVE_NET=1)\n";
|
||||
return;
|
||||
}
|
||||
auto client = invalid_key_client();
|
||||
try {
|
||||
Account(client).models();
|
||||
FAIL("expected 401");
|
||||
} catch (const ApiError& e) {
|
||||
std::cout << " GET /v1/models with an invalid key: " << e.http_status() << " " << e.message().substr(0, 40) << "\n";
|
||||
ASSERT_EQ(e.http_status(), 401);
|
||||
}
|
||||
ApiKeyCheck c = Account(client).check_api_key();
|
||||
std::cout << " POST /v1/check-api-key with an invalid key: valid=" << c.valid << "\n";
|
||||
ASSERT_FALSE(c.valid);
|
||||
try {
|
||||
Chat(client).create(ChatParams::prompt("hi"));
|
||||
FAIL("expected 401");
|
||||
} catch (const ApiError& e) {
|
||||
ASSERT_EQ(e.http_status(), 401);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(cohere_live, key_check_models_and_one_tiny_chat) {
|
||||
Platform p = Platform::from_env();
|
||||
if (!net() || !p.configured()) {
|
||||
std::cout << "SKIP cohere_live.key_check_models_and_one_tiny_chat (set MOLO_LIVE_NET=1 and COHERE_API_KEY)\n";
|
||||
return;
|
||||
}
|
||||
Account acct(p.client);
|
||||
ApiKeyCheck c = acct.check_api_key();
|
||||
std::cout << " key valid=" << c.valid << "\n";
|
||||
ASSERT_TRUE(c.valid);
|
||||
ModelList models = acct.all_models("chat");
|
||||
std::cout << " chat models: " << models.models.size() << "\n";
|
||||
ASSERT_TRUE(!models.models.empty());
|
||||
ChatParams params = ChatParams::prompt("Reply with the single word: ok");
|
||||
params.max_tokens = 16;
|
||||
ChatResult r = Chat(p.client).create(params);
|
||||
std::cout << " chat finish=" << r.finish_reason << " tokens=" << r.usage.input_tokens + r.usage.output_tokens << "\n";
|
||||
ASSERT_TRUE(r.usage.present);
|
||||
}
|
||||
|
||||
TEST(cohere_live, paid_embed_and_rerank_one_smallest_request_each) {
|
||||
Platform p = Platform::from_env();
|
||||
if (!net() || !paid() || !p.configured()) {
|
||||
std::cout << "SKIP cohere_live.paid_embed_and_rerank_one_smallest_request_each (set MOLO_LIVE_NET=1, MOLO_LIVE_PAID=1 and COHERE_API_KEY)\n";
|
||||
return;
|
||||
}
|
||||
EmbedParams e;
|
||||
e.texts = {"hello"};
|
||||
e.embedding_types = {"float"};
|
||||
EmbedResult er = Embeddings(p.client).embed(e);
|
||||
ASSERT_EQ(er.floats().size(), 1u);
|
||||
RerankParams rp;
|
||||
rp.query = "capital of France";
|
||||
rp.documents = {"Paris is the capital of France.", "Bananas are yellow."};
|
||||
RerankResult rr = Rerank(p.client).rerank(rp);
|
||||
ASSERT_EQ(rr.hits.size(), 2u);
|
||||
ASSERT_EQ(rr.hits[0].index, 0);
|
||||
}
|
||||
Reference in New Issue
Block a user