mirror of
https://github.com/wolfpld/tracy.git
synced 2026-10-16 22:05:34 +00:00
Extract calculation of max tool output size.
This commit is contained in:
@@ -83,6 +83,16 @@ std::string TracyLlmTools::GetCurrentTime()
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int TracyLlmTools::CalcMaxSize() const
|
||||
{
|
||||
// Limit the size of the response to avoid exceeding the context size
|
||||
// Assume average token size is 4 bytes. Make space for 3 articles to be retrieved.
|
||||
assert( m_modelMaxContext != 0 );
|
||||
const auto ctxSize = std::min( m_modelMaxContext, s_config.llmContext );
|
||||
const auto maxSize = ( ctxSize * 4 ) / 3;
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
static size_t WriteFn( void* _data, size_t size, size_t num, void* ptr )
|
||||
{
|
||||
const auto data = (unsigned char*)_data;
|
||||
@@ -195,11 +205,10 @@ std::string TracyLlmTools::GetWikipedia( std::string page, const std::string& la
|
||||
std::ranges::replace( page, ' ', '_' );
|
||||
auto res = FetchWebPage( "https://" + lang + ".wikipedia.org/w/rest.php/v1/page/" + page );
|
||||
|
||||
// Limit the size of the response to avoid exceeding the context size
|
||||
// Assume average token size is 4 bytes. Make space for 3 articles to be retrieved.
|
||||
assert( m_modelMaxContext != 0 );
|
||||
const auto ctxSize = std::min( m_modelMaxContext, s_config.llmContext );
|
||||
const auto maxSize = ( ctxSize * 4 ) / 3;
|
||||
const auto maxSize = CalcMaxSize();
|
||||
if( res.size() > maxSize ) res = res.substr( 0, maxSize );
|
||||
return res;
|
||||
}
|
||||
|
||||
if( res.size() > maxSize ) res = res.substr( 0, maxSize );
|
||||
return res;
|
||||
|
||||
@@ -26,6 +26,8 @@ public:
|
||||
bool m_netAccess = true;
|
||||
|
||||
private:
|
||||
[[nodiscard]] int CalcMaxSize() const;
|
||||
|
||||
std::string FetchWebPage( const std::string& url );
|
||||
ToolReply SearchWikipedia( std::string query, const std::string& lang );
|
||||
std::string GetWikipedia( std::string page, const std::string& lang );
|
||||
|
||||
Reference in New Issue
Block a user