我在 Python 中使用 Langchain 和 Gradio 接口。我制作了一个对话代理,并尝试将其响应传输到 Gradio 聊天机器人界面。我查看了 Langchain 文档,但找不到使用代理实现流式传输的示例。这是我的代码的一些部分:
# Loading the LLM
def load_llm():
return AzureChatOpenAI(
temperature=hparams["temperature"],
top_p=hparams["top_p"],
max_tokens=hparams["max_tokens"],
presence_penalty=hparams["presence_penalty"],
frequency_penalty=hparams["freq_penaulty"],
streaming=True,
callback_manager=CallbackManager([StreamingStdOutCallbackHandler()]),
verbose=True,
model_name=hparams["model"],
deployment_name = models_dict[hparams["model"]],
)
# Loading the agent
def load_chain(memory, sys_msg, llm):
"""Logic for loading the chain you want to use should go here."""
agent_chain = initialize_agent(tools,
llm,
agent="conversational-react-description",
verbose=True,
memory=memory,
agent_kwargs = {"added_prompt": sys_msg},
streaming=True,
)
return agent_chain
# Creating the chatbot to be used in Gradio.
class ChatWrapper:
def __init__(self, …Run Code Online (Sandbox Code Playgroud) 我正在尝试加载地图并在用户位置上显示初始位置,并使用 SwiftUI 在地图上显示用户的位置。我不知道如何在 SwiftUI 中做到这一点。
我试图将 'view.showsUserLocation = true' 放在 updateUIView 函数中,但它不起作用。
import SwiftUI
import MapKit
struct MapView : UIViewRepresentable {
func makeUIView(context: Context) -> MKMapView {
MKMapView(frame: .zero)
}
func updateUIView(_ view: MKMapView, context: Context) {
view.showsUserLocation = true
let coordinate = CLLocationCoordinate2D(
latitude: 34.011286, longitude: -116.166868)
let span = MKCoordinateSpan(latitudeDelta: 2.0, longitudeDelta: 2.0)
let region = MKCoordinateRegion(center: view.userLocation.location?.coordinate ?? coordinate, span: span)
view.setRegion(region, animated: true)
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试打印它时,该位置为零。
我正在尝试在我正在开发的Mac应用程序中运行终端命令.终端命令是:
sudo sysctl -w net.inet.tcp.delayed_ack=0
Run Code Online (Sandbox Code Playgroud)
我尝试过使用NSTask,但似乎每次都在做错事.
我只想运行此命令并打印输出.感谢您的关注.
PS.这是我当前的代码看起来像(感谢您的回复):
let task = NSTask()
task.launchPath = "/usr/sbin/sysctl"
task.arguments = ["-w", "net.inet.tcp.delayed_ack=0"]
let pipe = NSPipe()
task.standardOutput = pipe
task.standardError = pipe
task.launch()
task.waitUntilExit()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output: String = NSString(data: data, encoding: NSUTF8StringEncoding) as! String
Run Code Online (Sandbox Code Playgroud)
我在输出中收到以下消息:
net.inet.tcp.delayed_ack:3
sysctl:net.inet.tcp.delayed_ack = 0:不允许操作
我正在使用SwiftUI显示地图,如果用户点击了注释,它将在VStack中弹出详细视图。我已经制作了地图视图,并在另一个SwiftUI文件中插入了注释。我还做了详细视图。
如何在主视图文件中访问该地图的注释,以定义一个.tapaction,以便他们将其用于详细视图?
我尝试将视图定义为MKMapView,但无法在另一个SwiftUI视图中为UIViewRepresentable做到这一点。
主视图(ContentView)代码为:
struct ContentView: View {
@State private var chosen = false
var body: some View {
VStack {
MapView()
.edgesIgnoringSafeArea(.top)
.frame(height: chosen ? 600:nil)
.tapAction {
withAnimation{ self.chosen.toggle()}
}
if chosen {
ExtractedView()
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
MapView代码为:
struct MapView : UIViewRepresentable {
@State private var userLocationIsEnabled = false
var locationManager = CLLocationManager()
func makeUIView(context: Context) -> MKMapView {
MKMapView(frame: .zero)
}
func updateUIView(_ view: MKMapView, context: Context) {
view.showsUserLocation = true
.
.
.
let sampleCoordinates …Run Code Online (Sandbox Code Playgroud)