Commit 247eee9
committed
fix(langchain-classic): fix init_chat_model for HuggingFace models
Fixes #28226
The issue was that init_chat_model didn't properly handle HuggingFace
model initialization. The main problems were:
1. HuggingFacePipeline.from_model_id requires a 'task' parameter, but
it wasn't being provided (defaults to 'text-generation' for chat models)
2. Parameters needed to be properly separated between HuggingFacePipeline
and ChatHuggingFace - generation parameters (temperature, max_tokens,
etc.) should go to pipeline_kwargs, while other parameters (timeout,
max_retries) should go to ChatHuggingFace
3. max_tokens needs to be mapped to max_new_tokens for HuggingFace pipeline
Changes:
- Extract task parameter with default 'text-generation'
- Properly separate pipeline-specific kwargs from ChatHuggingFace kwargs
- Map generation parameters to pipeline_kwargs
- Map max_tokens to max_new_tokens for HuggingFace pipeline
- Add test to verify the fix works correctly1 parent e0ecfa9 commit 247eee9
1 file changed
+36
-27
lines changedLines changed: 36 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
100 | 109 | | |
101 | 110 | | |
102 | 111 | | |
| |||
0 commit comments