MCPcopy Index your code
hub / github.com/coder/coder / extractContextLimit

Function extractContextLimit

coderd/x/chatd/chatloop/chatloop.go:1995–2019  ·  view source on GitHub ↗
(metadata fantasy.ProviderMetadata)

Source from the content-addressed store, hash-verified

1993}
1994
1995func extractContextLimit(metadata fantasy.ProviderMetadata) sql.NullInt64 {
1996 if len(metadata) == 0 {
1997 return sql.NullInt64{}
1998 }
1999
2000 encoded, err := json.Marshal(metadata)
2001 if err != nil || len(encoded) == 0 {
2002 return sql.NullInt64{}
2003 }
2004
2005 var payload any
2006 if err := json.Unmarshal(encoded, &payload); err != nil {
2007 return sql.NullInt64{}
2008 }
2009
2010 limit, ok := findContextLimitValue(payload)
2011 if !ok {
2012 return sql.NullInt64{}
2013 }
2014
2015 return sql.NullInt64{
2016 Int64: limit,
2017 Valid: true,
2018 }
2019}
2020
2021func extractContextLimitWithFallback(metadata fantasy.ProviderMetadata, fallback int64) sql.NullInt64 {
2022 contextLimit := extractContextLimit(metadata)

Callers 3

TestExtractContextLimitFunction · 0.85
tryCompactFunction · 0.85

Calls 3

findContextLimitValueFunction · 0.85
MarshalMethod · 0.45
UnmarshalMethod · 0.45

Tested by 1

TestExtractContextLimitFunction · 0.68