Refactored LLM handling to use updated langchaingo models and tools, replacing gollm dependencies. Introduced agent-related utilities, tools, and counters for better modular functionality. Added a parser for LLM model configuration and revamped the answering mechanism with enhanced support for tool-based interaction.
26 lines
434 B
Go
26 lines
434 B
Go
package agent
|
|
|
|
import "sync/atomic"
|
|
|
|
type Counter struct {
|
|
atomic.Int32
|
|
}
|
|
|
|
// Take will attempt to take an item from the counter. If the counter is zero, it will return false.
|
|
func (c *Counter) Take() bool {
|
|
for {
|
|
current := c.Load()
|
|
if current <= 0 {
|
|
return false
|
|
}
|
|
if c.CompareAndSwap(current, current-1) {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
|
|
// Return will return an item to the counter.
|
|
func (c *Counter) Return() {
|
|
c.Add(1)
|
|
}
|