152 Commits

Author SHA1 Message Date
Travis Cline db2a947ba4 agents: fix ChainCallOption silent failure (#1420)
* llms/openai: sanitize HTTP errors to prevent API key exposure (#1393)

Fix security issue where context deadline errors could expose API keys and
sensitive request details in error messages. Added sanitizeHTTPError function
to detect context timeouts and network errors, then return generic error
messages without exposing sensitive information.

Changes:
- Added sanitizeHTTPError() function to sanitize HTTP client errors
- Updated chat.go to use sanitizeHTTPError() for http.Do() errors
- Updated embeddings.go to use sanitizeHTTPError() for http.Do() errors
- Added comprehensive test cases to prevent regression

* agents: fix ChainCallOption silent failure (#1416)

Fix issue where ChainCallOption parameters were silently ignored by Executor.Call() and Agent implementations.

Changes:
- Updated Agent.Plan() interface signature to accept variadic ChainCallOption parameters
- Updated Executor.Call() to accept and propagate options to Agent.Plan()
- Updated Executor.doIteration() to propagate options through the chain
- Updated OneShotZeroAgent.Plan() to accept and pass options to chains.Predict()
- Updated ConversationalAgent.Plan() to accept and pass options to chains.Predict()
- Updated OpenAIFunctionsAgent.Plan() to accept and pass options to LLM.GenerateContent()
- Exported GetLLMCallOptions() function for option conversion (was getLLMCallOptions)
- Updated test mock to match new Agent interface signature

Now users can pass LLM configuration options (temperature, max tokens, etc.) through executors to agents.
2025-10-19 17:03:11 -07:00
Travis Cline dd61fd90f4 test: improve test resilience and update provider APIs (#1377)
test: improve test resilience with better HTTP recording handling

Add hasExistingRecording helper to detect available recordings and skip tests
gracefully when recordings are unavailable. Replace generic credential checks
with specific recording validation and provide clear error messages.
2025-08-22 18:13:13 +02:00
Travis Cline 99951bca92 httprr: improve test recording stability and add utilities (#1368)
* build: add examples-updater tool and update examples to v0.1.14-pre.1

Add a new tool to automate updating langchaingo version references in example
projects and use it to update all examples to v0.1.14-pre.1. The tool also
removes temporary replace directives that are no longer needed.

- Add update-examples Makefile target that runs the new tool
- Create internal/devtools/examples-updater implementation
- Update all example go.mod files to reference v0.1.14-pre.1
- Remove replace directives in googleai and vertex examples
- Update dependencies in main go.mod/go.sum

* httprr: improve header normalization and test container setup

Add header normalization to make HTTP recordings more stable:
- Add normalizeGoogleAPIClientHeader and normalizeVersionHeader functions
- Normalize User-Agent, x-goog-api-client and other version headers
- Remove OpenAI-Project header for consistency
- Preserve body for both replay lookup and recording
- Add comprehensive tests for header normalization

Improve testcontainer environment detection:
- Better handling of non-standard Docker socket paths
- Disable Ryuk reaper by default for resource efficiency
- Add verbose logging option via environment variable

* httputil: add ApiKeyTransport for query parameter API keys

Add a reusable ApiKeyTransport that adds API keys to URL query parameters:
- Create ApiKeyTransport implementation in httputil package
- Add comprehensive tests for the new transport
- Refactor googleai_test.go to use the shared transport
- Update chains/llm_test.go to use ApiKeyTransport with proper key scrubbing

This improves how API keys are handled with client libraries that don't
properly set keys when using custom HTTP clients, particularly useful
with httprr for testing Google API integrations.

* openai: remove duplicate MaxTokens field assignment

Remove redundant assignment where both MaxTokens and MaxCompletionTokens
were being set to the same value. MaxCompletionTokens is the preferred
field name that reflects OpenAI's API changes, while MaxTokens was
previously kept for backward compatibility.

* vectorstores/maridadb: add test infrastructure for MariaDB vectorstore

Add TestMain function for MariaDB vectorstore tests that ensures the proper
test environment is set up using the testctr package. This enables consistent
test container setup and teardown for MariaDB integration tests.

* all: normalize all httprr recordings for consistency

Update test recordings across all packages to use normalized headers:
- Standardize User-Agent to 'langchaingo-httprr'
- Normalize version information in x-goog-api-client headers
- Remove OpenAI-Project headers for consistency
- Fix deprecated Anthropic completion API tests
- Update HuggingFace test recordings with valid responses

These changes make test recordings stable across dependency updates
and different environments, preventing test failures from version changes.

* devtools: add utility tool for normalizing httprr test recordings

Add a command-line tool that standardizes version information in httprr recordings:
- Normalizes x-goog-api-client headers to use placeholder versions
- Standardizes x-amz-user-agent headers for consistency
- Replaces Go version strings with generic placeholders
- Supports dry-run mode to preview changes without modifying files
- Includes verbose output option for detailed change reporting

This tool helps maintain consistent test recordings across different environments
and dependency versions, preventing test failures from version changes.

* llms/openai: update OpenAI embedding test to use text-embedding-3-small model

Update the embedding test to use the current text-embedding-3-small model:
- Change model from text-embedding-ada-002 to text-embedding-3-small
- Adjust dimensions parameter from 1234 to 256 to match model capabilities
- Update test recording with appropriate response data

This change ensures tests remain compatible with OpenAI's current embedding
models and prevents test failures from API version changes.
2025-08-18 19:41:52 +02:00
Travis Cline 77504b877f all: expand test coverage (#1312)
* scripts: cleanup test scripts
* lint: add test pattern and architectural linting
* internal/httprr: expand httprr testing
* test: add comprehensive unit test coverage
* docs: add comprehensive testing guide to CONTRIBUTING.md
* examples: standardize module versions and cleanup dependencies
* all: re-record several httprr recordings
2025-06-16 18:14:02 +02:00
Travis Cline c544fb77bd all: add broad httprr coverage, update dependencies, organize go.mod file, bump to 1.23 (#1299)
* all: add broad httprr coverage, update dependencies, organize go.mod file, bump to 1.23

update go version to 1.23
add lots of test coverage via httprr recordings
update dependencies and organize go.mod
add testutil/testctr which helps work around a testcontainers-go+colima bug
expand the huggingface implementation and tests
expand capabilities of the ollama package
2025-06-04 11:41:45 -07:00
Travis Cline 6c81282073 examples: Fix examples and complete linting upgrade (#1288)
* examples: update examples, clean up module declarations

- Fix and relax lint rules (for now)
- Clean up and fix module declarations
- Add .gitattributes to mark go.sum as binary

* ci: separate and enhance CI workflows

- Split example builds into dedicated workflow
- Add comprehensive test coverage reporting
- Improve CI structure with matrix testing
- Add race condition testing
- Add automated PR coverage comments

* test: improve test reliability and agent message handling

- Simplify MRKL agent test to use basic math calculation
- Update OpenAI functions agent to use ToolChatMessage
- Add proper environment checks for Zep integration tests

* agents: fix issue in tool call handling for openai function agent
2025-06-03 07:52:03 -07:00
Manuel de la Peña 8d4c17fc73 ci: migrate linting golangci-lint to v2.0.2 (#1217)
* chore: use slices and maps packages

* chore: skip embedded type

* chore: use fmt.Fprint instead

* chore: use switch

* chore: reorder imports

* chore: add white lines

* chore: use t.Setenv

* chore: excplicitly omit non used param

* chore: use t.TempDir

* chore: use maps package

* chore: migrate golangci-lint config file

Run: "golangci-lint migrate -c .golangci.yaml --skip-validation"

* chore: bump golangci-lint action to v7
2025-04-12 01:54:50 -07:00
takeshi.nakata f7fac2246e chains_test: use mutex to lock 2024-12-02 18:02:28 +09:00
Travis Cline bf1667feaf lint: fixup lint settings (#1018) 2024-09-13 04:39:28 +00:00
Pavlo Paliychuk 89195f8554 memory: Add Zep Cloud integration (#746)
* memory: Add Zep Cloud integration
2024-06-14 23:19:11 -04:00
Eli Bendersky 556a263188 schema: move Chat* types to llms (#757)
* schema: move Chat* types to llms

This prevents a circular dependency or code duplication when using Tools
2024-04-16 23:35:51 -07:00
Travis Cline b6ba6693d3 tooling: Update minimum go version to 1.22, update golangci-lint (#722)
* go: Update to go 1.22, update golangci-lint config

* lint: Address various lint issues

* chains: fix lint complaint in TestApplyWithCanceledContext

* lint: Address addtional lint issues

* lint: Address addtional lint issues

* tools: update golangci-lint to 1.57
2024-03-26 20:31:20 +00:00
Dévin.YF ca2969cec9 tool: sql_database generate sql-query filter redundant text (#612)
* tool: sql_database generate sql-query filter redundant text
2024-03-13 15:10:15 -07:00
Abirdcfly 17002cc725 chains: fix add ignore StreamingFunc (#639)
Signed-off-by: Abirdcfly <fp544037857@gmail.com>
2024-03-05 06:48:21 -08:00
Eli Bendersky 22864933b6 Fix llm_math_chain example (#634)
* Fix llm_math_chain example

* Better error message from Starlark eval
* Fix to a sample that actually works
2024-02-24 06:17:51 -08:00
Eli Bendersky 76fb641fdd Update comments, bump example dependencies and clarify chain example (#633)
Update comments, bump example dependencies and clarify chain example a bit
2024-02-24 05:52:30 -08:00
Eli Bendersky 7214d8a1f5 chains: fix issue with overriding defaults in chainCallOption (#632)
Updates #626

Fixes #603
Fixes #604
Fixes #594
2024-02-23 13:45:25 -08:00
Eli Bendersky 9aa84dda2b chains: add test with GoogleAI (#628)
Resurrect test from #625, but add explicit settings until #626 is resolved
2024-02-22 17:48:57 -08:00
Eli Bendersky 55e1a97000 Revert "googleai: fix options need add default value" (#627)
This reverts commit 40d40ea188.
2024-02-22 09:34:44 -08:00
Abirdcfly 40d40ea188 googleai: fix options need add default value
Signed-off-by: Abirdcfly <fp544037857@gmail.com>
2024-02-21 22:09:10 +08:00
Eli Bendersky 59a4f99c25 llms: officially deprecate Call method on the interface (#555) 2024-01-25 17:30:09 +00:00
Eli Bendersky cbab2c9b77 Deprecate the LLM interface
It's just an alias for Model now
2024-01-17 14:09:45 -08:00
Eli Bendersky 8b30d4b229 all: clean up now unused types Generation and LLMResult 2024-01-17 07:07:35 -08:00
Eli Bendersky 0e4d69e6f1 chains: dummy implementation of GenerateContent because of new interfaces 2024-01-17 06:01:45 -08:00
Eli Bendersky 05219dd263 Clean up GeneratePrompt -- unused code, and simplify caller (#489) 2024-01-04 06:58:39 -08:00
Eli Bendersky b5c16493c2 Clear out GetNumTokens (#483)
It's not used and not implemented correctly for almost any model.

If this is deemed useful, it will be more correct to expose a model name
from the LLM (or cliena?) and then invoke a standalone function familiar
with non-openai models.

Re #482
2024-01-03 12:35:26 -08:00
Eli Bendersky 435467ab33 Resolve lint complaints and gofumpt 2023-12-29 09:56:26 -08:00
Eli Bendersky ab14227446 Remove mentions of the LanguageModel interface 2023-12-29 09:44:57 -08:00
Eli Bendersky 93cea28bfe Refactor usage of LanguageModel out
Replace it by LLM and adjust code and tests accordingly

re #465
2023-12-29 09:35:52 -08:00
Eli Bendersky eb58836512 Skip tests that are currently failing (#415) (#466) 2023-12-28 21:02:13 -08:00
chyroc 310afd2c66 promps: move prompts to embedded text files (#451) 2023-12-28 16:55:43 -08:00
chyroc 534f75725e Feat: callbacks.Handler support handle error (#457)
Feat: support HandleLLMError for llms.LLM
2023-12-28 15:22:05 -08:00
h3l 284a853cc9 support callback handler to llm chain (#461)
* support callback handler to llm chain

* fix golint

---------

Co-authored-by: lvzhong <lvzhong@bytedance.com>
2023-12-28 15:17:37 -08:00
chyroc 99bb50d3c7 Feat: use chains callback as streaming func (#447) 2023-12-24 21:05:42 -08:00
chyroc 55f772c21a Docs: fix comment typo (#442)
* Docs: fix comment typo

* docs: a llm -> an LLM

---------

Co-authored-by: Travis Cline <travis.cline@gmail.com>
2023-12-20 19:57:37 +00:00
Bruce Bai eb17026117 test: fix api chain test error (#414) (#434) 2023-12-19 13:48:48 -08:00
Aksel 543f504f47 agents: add parser error handler (#345)
* agents: add ParserErrorHandler

* chains: return result when error in chain

* agents: fix lint
2023-12-04 22:38:29 -08:00
Ismail 80f9027554 fix: golangci-lint v1.55 errors 2023-12-04 22:38:28 -08:00
Amir Karimi 225316c84e chains: added constitutional chain. refactored few shot prompt (#316) 2023-12-04 22:38:28 -08:00
Edocevol 2d98503482 remove last separator (#286) 2023-09-22 10:17:08 -07:00
Edocevol fd158b5de8 add chain call option: WithTopP (#288) 2023-09-22 10:16:45 -07:00
Travis Cline c5b84faa54 callbacks: Include context 2023-08-25 19:14:02 -07:00
FluffyKebab b2dee18c4b callbacks: nolint forbidigo in logger 2023-08-25 19:00:43 -07:00
FluffyKebab 199046e5b7 callbacks: improve logging formating and docs 2023-08-25 19:00:21 -07:00
FluffyKebab 5e3175bf25 add option for callbacks when calling chain 2023-08-25 19:00:21 -07:00
Nikola Zivkovic 16e3fd2870 Merge branch 'main' into embeddings-azure-openai 2023-08-17 19:55:05 +02:00
zivkovicn fbf9de856c embeddings-azure-openai | lint 2023-08-17 19:50:43 +02:00
zivkovicn 508171f161 embeddings-azure-openai | fixing issues 2023-08-17 19:45:52 +02:00
edocevol 36bfa3c156 memory: add context support 2023-08-14 12:45:54 +08:00
Travis Cline 8f101609f6 Merge pull request #225 from nidzola/refactor-and-fix-openaichat
embeddings & llm: Creating the actual embeddings for the OpenAI chat, splitting llms for openai
2023-07-30 19:48:23 -07:00