当前位置: 首页 > article >正文

Xamarin.Android实现本地化部署DeepSeek的对话功能

1、背景

时间飞逝啊!春节期间大火的DeepSeek,假期还没结束,就赶紧自己部署了一个R1的最低版本(1.5B),顺便在App上通过API实现与本地DeepSeek的对话功能。这几天睡眠不好,写了几篇,正好总结及记录一下吧

2、效果

整体的效果如视频所示。【说明】当时整的时候,只是一个最简单的http请求,没有使用SignalR,改天再加上试试

Xamarin.Android实现DeepSeek的对话功能

3、具体实现

3.1 .9.png图(点九图)

首先是对话框,就是下图中的聊天框的蓝色和灰色的区域,在Android开发中经常使用后缀名称为.9.png的图片,作为存放文字的区域。
在这里插入图片描述
先说一下.9.png的逻辑
在这里插入图片描述
上面的横线,代表整个对话框左右移动的区域,左侧是上下移动的区域;而右面的横线则是文字在垂直方向的存放区域,下方的则是文字在水平方向的存放区域。大体如下图所示
在这里插入图片描述
如何画出这个界面,网上的方法有很多,这里介绍一个很简单的。登录这个网址:Android Asset Studio,选择这个,进行尝试即可,非常简单。这个网站还有很多其他功能,甚至好用。
在这里插入图片描述
将制作完成的.9.png图片导入至项目中既可。左右各一个.9图
在这里插入图片描述
这样,前期的准备工作基本完成了

3.2 App界面实现

整体界面很简单,整体的布局示意图如图所示
在这里插入图片描述
主要分为两个文件实现:deepseek_layout.xmldeepseek_dialog_layout.xml,其中前者为整体的布局文件,后者为ListView的adapter的配套布局文件。两者的代码如下:
deepseek_layout.xml代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="#d8e0e8"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ListView
        android:id="@+id/msg_list_view"
        android:divider="#0000"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp"/>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:id="@+id/input_text"
            android:hint="请输入您的问题..."
            android:maxLines="2"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_width="0dp" />
        <Button
            android:id="@+id/send_btn"
            android:text="发送"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </LinearLayout>
</LinearLayout>

deepseek_dialog_layout.xml代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp">

    <TextView
        android:textAlignment="center"
        android:id="@+id/currentDateTime"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <LinearLayout
        android:id="@+id/left_layout"
        android:layout_gravity="left"
        android:background="@drawable/msg_left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView
            android:layout_gravity="center"
             android:layout_margin="10dp"
             android:textColor="#fff"
            android:id="@+id/left_msg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    </LinearLayout>
    <LinearLayout
         android:id="@+id/right_layout"
        android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="right"
         android:background="@drawable/msg_right" >
         <TextView
             android:id="@+id/right_msg"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center"
            android:layout_margin="10dp" />
     </LinearLayout>

</LinearLayout>

然后deepseek的请求,并完成ListView的赋值。关于deepseek的接口调用,参见使用C#控制台调用本地部署的DeepSeek。最终完成本项目的效果。

4、参考资料

1、.9.PNG是啥?


http://www.kler.cn/a/599518.html

相关文章:

  • 【DFS】羌笛何须怨杨柳,春风不度玉门关 - 4. 二叉树中的深搜
  • STM32八股【3】------RAM和片上FLASH
  • System.arraycopy 在音视频处理中的应用
  • TDengine 用户权限管理
  • Elasticsearch:设置向量搜索
  • 【机器学习基础 4】 Pandas库
  • 大模型应用(Java)2025/3/24
  • [Lc18_BFS拓扑排序] 邻接表 | 课程表I II
  • AI Tokenization
  • windows与linux开发板之间设置nfs共享文件
  • 23种设计模式-外观(Facade)设计模式
  • C#中 String类API(函数)
  • 数据结构八股
  • Android11-12-13 替换系统默认壁纸
  • 图解AUTOSAR_CP_LargeDataCOM
  • 构建智能变量命名助手:解决 FastAPI 与 Ollama 集成难题
  • 基础-语音是怎么进到LLM里面的
  • 平芯微PW2609A过压保护芯片应用电路
  • 安科瑞新能源防逆流解决方案:守护电网安全,赋能绿色能源利用
  • Packaging Process