-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
message-context filter put messageGroup into context
- Loading branch information
Showing
6 changed files
with
174 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ctxhelper | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/erda-project/erda/internal/apps/ai-proxy/models/message" | ||
"github.com/erda-project/erda/internal/apps/ai-proxy/vars" | ||
"github.com/erda-project/erda/pkg/reverseproxy" | ||
) | ||
|
||
func GetMessageGroup(ctx context.Context) (*message.Group, bool) { | ||
value, ok := ctx.Value(reverseproxy.CtxKeyMap{}).(*sync.Map).Load(vars.MapKeyMessageGroup{}) | ||
if !ok || value == nil { | ||
return nil, false | ||
} | ||
mg, ok := value.(*message.Group) | ||
if !ok { | ||
return nil, false | ||
} | ||
return mg, true | ||
} | ||
|
||
func PutMessageGroup(ctx context.Context, mg message.Group) { | ||
m := ctx.Value(reverseproxy.CtxKeyMap{}).(*sync.Map) | ||
m.Store(vars.MapKeyMessageGroup{}, &mg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ctxhelper | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/erda-project/erda/internal/apps/ai-proxy/vars" | ||
"github.com/erda-project/erda/pkg/reverseproxy" | ||
) | ||
|
||
func GetUserPrompt(ctx context.Context) (string, bool) { | ||
value, ok := ctx.Value(reverseproxy.CtxKeyMap{}).(*sync.Map).Load(vars.MapKeyUserPrompt{}) | ||
if !ok || value == nil { | ||
return "", false | ||
} | ||
prompt, ok := value.(string) | ||
if !ok { | ||
return "", false | ||
} | ||
return prompt, true | ||
} | ||
|
||
func PutUserPrompt(ctx context.Context, prompt string) { | ||
m := ctx.Value(reverseproxy.CtxKeyMap{}).(*sync.Map) | ||
m.Store(vars.MapKeyUserPrompt{}, prompt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package message | ||
|
||
type Group struct { | ||
AllMessages Messages // use this directly if you are not care about the details | ||
|
||
// pay attention to the order | ||
SystemMessage *Message | ||
SessionTopicMessage *Message | ||
PromptTemplateMessages Messages | ||
SessionPreviousMessages Messages // from prompt template if provided in the http header | ||
RequestedMessages Messages // normally from body prompt field, user input | ||
} |